Skip to content

Commit

Permalink
输入参数校验
Browse files Browse the repository at this point in the history
  • Loading branch information
yihango committed Jun 2, 2021
1 parent 79cd8fa commit 5057ec2
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/LiteIM.CSRedisCore/CsRedisCoreImClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,27 @@ public class CsRedisCoreImClient : IImClient
public CsRedisCoreImClient(ICsRedisCoreImClientOptions options)
{
_options = options;
if (_options.Redis == null)
{
throw new ArgumentNullException(nameof(options.Redis), "ICsRedisCoreImClientOptions Redis 属性为空!");
}


_prefix = _options.Prefix;
_prefix = (_options.Prefix ?? string.Empty).Trim();
_redis = _options.Redis;
}


public virtual IEnumerable<string> GetClientListByOnline()
{
return _redis.HKeys(
_prefix.Online()
_prefix.CSRedisCoreOnline()
).Where(o => !string.IsNullOrWhiteSpace(o));
}

public virtual bool HasOnline(string clientId)
{
return _redis.HGet<int>(_prefix.Online(), clientId) > 0;
return _redis.HGet<int>(_prefix.CSRedisCoreOnline(), clientId) > 0;
}


Expand All @@ -46,15 +51,15 @@ public virtual void JoinChan(string clientId, string chan)
using (var pipe = _redis.StartPipe())
{
pipe.HSet(
_prefix.Chan(chan),
_prefix.CSRedisCoreChan(chan),
clientId,
0);
pipe.HSet(
_prefix.Client(clientId),
_prefix.CSRedisCoreClient(clientId),
chan,
0);
pipe.HIncrBy(
_prefix.ListChan(),
_prefix.CSRedisCoreListChan(),
chan,
1);
pipe.EndPipe();
Expand All @@ -72,16 +77,16 @@ public virtual void LeaveChan(string clientId, params string[] chans)
foreach (var chan in chans)
{
pipe.HDel(
_prefix.Chan(chan),
_prefix.CSRedisCoreChan(chan),
clientId
);
pipe.HDel(
_prefix.Client(clientId),
_prefix.CSRedisCoreClient(clientId),
chan
);
pipe.Eval(
string.Format(CsRedisCoreImConsts.LeaveChan, chan),
_prefix.ListChan()
_prefix.CSRedisCoreListChan()
);
}
pipe.EndPipe();
Expand All @@ -100,7 +105,7 @@ public virtual void LeaveChan(string clientId)
public virtual IEnumerable<string> GetChanClientList(string chan)
{
return _redis.HKeys(
_prefix.Chan(chan)
_prefix.CSRedisCoreChan(chan)
)
.AsEnumerable();
}
Expand All @@ -115,22 +120,22 @@ public virtual void ClearChanClient(string chan)
public virtual IEnumerable<(string chan, long online)> GetChanList()
{
var ret = _redis.HGetAll<long>(
_prefix.ListChan()
_prefix.CSRedisCoreListChan()
);
return ret.Select(a => (a.Key, a.Value));
}

public virtual IEnumerable<string> GetChanListByClientId(string clientId)
{
return _redis.HKeys(
_prefix.Client(clientId)
_prefix.CSRedisCoreClient(clientId)
).AsEnumerable();
}

public virtual long GetChanOnline(string chan)
{
return _redis.HGet<long>(
_prefix.ListChan(),
_prefix.CSRedisCoreListChan(),
chan);
}

Expand Down

0 comments on commit 5057ec2

Please sign in to comment.