public RespCommand(RedisCommandAttribute attrib, MethodInfo method, RespServer server) { _operation = (RespOperation)Delegate.CreateDelegate(typeof(RespOperation), server, method); Command = (string.IsNullOrWhiteSpace(attrib.Command) ? method.Name : attrib.Command).Trim().ToLowerInvariant(); CommandBytes = new CommandBytes(Command); SubCommand = attrib.SubCommand?.Trim()?.ToLowerInvariant(); Arity = attrib.Arity; MaxArgs = attrib.MaxArgs; LockFree = attrib.LockFree; _subcommands = null; }
private static Dictionary <CommandBytes, RespCommand> BuildCommands(RespServer server) { RedisCommandAttribute CheckSignatureAndGetAttribute(MethodInfo method) { if (method.ReturnType != typeof(TypedRedisValue)) { return(null); } var p = method.GetParameters(); if (p.Length != 2 || p[0].ParameterType != typeof(RedisClient) || p[1].ParameterType != typeof(RedisRequest)) { return(null); } return((RedisCommandAttribute)Attribute.GetCustomAttribute(method, typeof(RedisCommandAttribute))); } var grouped = from method in server.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) let attrib = CheckSignatureAndGetAttribute(method) where attrib != null select new RespCommand(attrib, method, server) into cmd group cmd by cmd.Command; var result = new Dictionary <CommandBytes, RespCommand>(); foreach (var grp in grouped) { RespCommand parent; if (grp.Any(x => x.IsSubCommand)) { var subs = grp.Where(x => x.IsSubCommand).ToArray(); parent = grp.SingleOrDefault(x => !x.IsSubCommand).WithSubCommands(subs); } else { parent = grp.Single(); } result.Add(new CommandBytes(grp.Key), parent); } return(result); }
public RespSocketServer(RespServer server) { _server = server ?? throw new ArgumentNullException(nameof(server)); server.Shutdown.ContinueWith((_, o) => ((SocketServer)o).Dispose(), this); }
private static Dictionary <CommandBytes, RespCommand> BuildCommands(RespServer server) {