Commit c7627a9a authored by Marc Gravell's avatar Marc Gravell

implement "pubsub numsub"; fix glitch in command tree (impacts "command" and...

implement "pubsub numsub"; fix glitch in command tree (impacts "command" and "command info" - gave nil name)
parent 536b10b1
...@@ -576,6 +576,15 @@ protected virtual TypedRedisValue Publish(RedisClient client, RedisRequest reque ...@@ -576,6 +576,15 @@ protected virtual TypedRedisValue Publish(RedisClient client, RedisRequest reque
return TypedRedisValue.Integer(count); return TypedRedisValue.Integer(count);
} }
[RedisCommand(-3, "pubsub", "numsub", LockFree = true)]
protected virtual TypedRedisValue PubsubNumsub(RedisClient client, RedisRequest request)
{
var channel = request.GetChannel(2, RedisChannel.PatternMode.Literal);
var subscribers = FilterSubscribers(channel);
int count = subscribers.Count;
if (count != 0) ArrayPool<RedisClient>.Shared.Return(subscribers.Array);
return TypedRedisValue.Integer(count);
}
[RedisCommand(1, LockFree = true)] [RedisCommand(1, LockFree = true)]
......
...@@ -52,7 +52,9 @@ RedisCommandAttribute CheckSignatureAndGetAttribute(MethodInfo method) ...@@ -52,7 +52,9 @@ RedisCommandAttribute CheckSignatureAndGetAttribute(MethodInfo method)
if (grp.Any(x => x.IsSubCommand)) if (grp.Any(x => x.IsSubCommand))
{ {
var subs = grp.Where(x => x.IsSubCommand).ToArray(); var subs = grp.Where(x => x.IsSubCommand).ToArray();
parent = grp.SingleOrDefault(x => !x.IsSubCommand).WithSubCommands(subs); parent = grp.SingleOrDefault(x => !x.IsSubCommand);
if (parent.Command == null) parent = new RespCommand(subs[0].Command);
parent = parent.WithSubCommands(subs);
} }
else else
{ {
...@@ -137,6 +139,13 @@ private RespCommand(RespCommand parent, RespCommand[] subs) ...@@ -137,6 +139,13 @@ private RespCommand(RespCommand parent, RespCommand[] subs)
_operation = parent._operation; _operation = parent._operation;
_subcommands = subs; _subcommands = subs;
} }
internal RespCommand(string command) : this()
{
Command = command;
Arity = -1;
MaxArgs = int.MaxValue;
}
public bool IsUnknown => _operation == null; public bool IsUnknown => _operation == null;
public RespCommand Resolve(in RedisRequest request) public RespCommand Resolve(in RedisRequest request)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment