RedisCommand returns Array reply of details about all Redis commands
(ctx *Context)
| 229 | |
| 230 | // RedisCommand returns Array reply of details about all Redis commands |
| 231 | func RedisCommand(ctx *Context) { |
| 232 | count := func(ctx *Context) { |
| 233 | resp.ReplyInteger(ctx.Out, int64(len(commands))) |
| 234 | } |
| 235 | getkeys := func(ctx *Context) { |
| 236 | args := ctx.Args[1:] |
| 237 | if len(args) == 0 { |
| 238 | resp.ReplyError(ctx.Out, "ERR Unknown subcommand or wrong number of arguments.") |
| 239 | return |
| 240 | } |
| 241 | name := args[0] |
| 242 | cmdInfo, ok := commands[name] |
| 243 | if !ok { |
| 244 | resp.ReplyError(ctx.Out, "ERR Invalid command specified") |
| 245 | return |
| 246 | } |
| 247 | |
| 248 | if cmdInfo.Cons.Arity > 0 && len(args) != cmdInfo.Cons.Arity { |
| 249 | resp.ReplyError(ctx.Out, "ERR Invalid number of arguments specified for command") |
| 250 | return |
| 251 | } |
| 252 | if cmdInfo.Cons.Arity < 0 && len(args) < -cmdInfo.Cons.Arity { |
| 253 | resp.ReplyError(ctx.Out, "ERR Invalid number of arguments specified for command") |
| 254 | return |
| 255 | } |
| 256 | var keys []string |
| 257 | last := cmdInfo.Cons.LastKey |
| 258 | if last < 0 { |
| 259 | last += len(args) |
| 260 | } |
| 261 | for i := cmdInfo.Cons.FirstKey; i <= last; i += cmdInfo.Cons.KeyStep { |
| 262 | keys = append(keys, args[i]) |
| 263 | } |
| 264 | resp.ReplyArray(ctx.Out, len(keys)) |
| 265 | for _, key := range keys { |
| 266 | resp.ReplyBulkString(ctx.Out, key) |
| 267 | } |
| 268 | } |
| 269 | info := func(ctx *Context) { |
| 270 | names := ctx.Args[1:] |
| 271 | resp.ReplyArray(ctx.Out, len(names)) |
| 272 | for _, name := range names { |
| 273 | if cmd, ok := commands[name]; ok { |
| 274 | resp.ReplyArray(ctx.Out, 6) |
| 275 | resp.ReplyBulkString(ctx.Out, name) |
| 276 | resp.ReplyInteger(ctx.Out, int64(cmd.Cons.Arity)) |
| 277 | |
| 278 | flags := parseFlags(cmd.Cons.Flags) |
| 279 | resp.ReplyArray(ctx.Out, len(flags)) |
| 280 | for i := range flags { |
| 281 | resp.ReplyBulkString(ctx.Out, flags[i]) |
| 282 | } |
| 283 | |
| 284 | resp.ReplyInteger(ctx.Out, int64(cmd.Cons.FirstKey)) |
| 285 | resp.ReplyInteger(ctx.Out, int64(cmd.Cons.LastKey)) |
| 286 | resp.ReplyInteger(ctx.Out, int64(cmd.Cons.KeyStep)) |
| 287 | } else { |
| 288 | resp.ReplyNullBulkString(ctx.Out) |
nothing calls this directly
no test coverage detected