COMMAND */
| 5483 | |
| 5484 | /* COMMAND <subcommand> <args> */ |
| 5485 | void commandCommand(client *c) { |
| 5486 | dictIterator *di; |
| 5487 | dictEntry *de; |
| 5488 | |
| 5489 | if (c->argc == 2 && !strcasecmp((const char*)ptrFromObj(c->argv[1]),"help")) { |
| 5490 | const char *help[] = { |
| 5491 | "(no subcommand)", |
| 5492 | " Return details about all KeyDB commands.", |
| 5493 | "COUNT", |
| 5494 | " Return the total number of commands in this KeyDB server.", |
| 5495 | "GETKEYS <full-command>", |
| 5496 | " Return the keys from a full KeyDB command.", |
| 5497 | "INFO [<command-name> ...]", |
| 5498 | " Return details about multiple KeyDB commands.", |
| 5499 | NULL |
| 5500 | }; |
| 5501 | addReplyHelp(c, help); |
| 5502 | } else if (c->argc == 1) { |
| 5503 | addReplyArrayLen(c, dictSize(g_pserver->commands)); |
| 5504 | di = dictGetIterator(g_pserver->commands); |
| 5505 | while ((de = dictNext(di)) != NULL) { |
| 5506 | addReplyCommand(c, (redisCommand*)dictGetVal(de)); |
| 5507 | } |
| 5508 | dictReleaseIterator(di); |
| 5509 | } else if (!strcasecmp((const char*)ptrFromObj(c->argv[1]), "info")) { |
| 5510 | int i; |
| 5511 | addReplyArrayLen(c, c->argc-2); |
| 5512 | for (i = 2; i < c->argc; i++) { |
| 5513 | addReplyCommand(c, (redisCommand*)dictFetchValue(g_pserver->commands, ptrFromObj(c->argv[i]))); |
| 5514 | } |
| 5515 | } else if (!strcasecmp((const char*)ptrFromObj(c->argv[1]), "count") && c->argc == 2) { |
| 5516 | addReplyLongLong(c, dictSize(g_pserver->commands)); |
| 5517 | } else if (!strcasecmp((const char*)ptrFromObj(c->argv[1]),"getkeys") && c->argc >= 3) { |
| 5518 | struct redisCommand *cmd = (redisCommand*)lookupCommand((sds)ptrFromObj(c->argv[2])); |
| 5519 | getKeysResult result = GETKEYS_RESULT_INIT; |
| 5520 | int j; |
| 5521 | |
| 5522 | if (!cmd) { |
| 5523 | addReplyError(c,"Invalid command specified"); |
| 5524 | return; |
| 5525 | } else if (cmd->getkeys_proc == NULL && cmd->firstkey == 0) { |
| 5526 | addReplyError(c,"The command has no key arguments"); |
| 5527 | return; |
| 5528 | } else if ((cmd->arity > 0 && cmd->arity != c->argc-2) || |
| 5529 | ((c->argc-2) < -cmd->arity)) |
| 5530 | { |
| 5531 | addReplyError(c,"Invalid number of arguments specified for command"); |
| 5532 | return; |
| 5533 | } |
| 5534 | |
| 5535 | if (!getKeysFromCommand(cmd,c->argv+2,c->argc-2,&result)) { |
| 5536 | addReplyError(c,"Invalid arguments specified for command"); |
| 5537 | } else { |
| 5538 | addReplyArrayLen(c,result.numkeys); |
| 5539 | for (j = 0; j < result.numkeys; j++) addReplyBulk(c,c->argv[result.keys[j]+2]); |
| 5540 | } |
| 5541 | getKeysFreeResult(&result); |
| 5542 | } else { |
nothing calls this directly
no test coverage detected