For a specified command, parse its arguments and return an array that * contains the indexes of all key name arguments. This function is * essnetially a more efficient way to do COMMAND GETKEYS. * * A NULL return value indicates the specified command has no keys, or * an error condition. Error conditions are indicated by setting errno * as folllows: * * * ENOENT: Specified command does not
| 8979 | * must explicitly call RM_Free() to free it. |
| 8980 | */ |
| 8981 | int *RM_GetCommandKeys(RedisModuleCtx *ctx, RedisModuleString **argv, int argc, int *num_keys) { |
| 8982 | UNUSED(ctx); |
| 8983 | struct redisCommand *cmd; |
| 8984 | int *res = NULL; |
| 8985 | |
| 8986 | /* Find command */ |
| 8987 | if ((cmd = lookupCommand(argv[0]->ptr)) == NULL) { |
| 8988 | errno = ENOENT; |
| 8989 | return NULL; |
| 8990 | } |
| 8991 | |
| 8992 | /* Bail out if command has no keys */ |
| 8993 | if (cmd->getkeys_proc == NULL && cmd->firstkey == 0) { |
| 8994 | errno = 0; |
| 8995 | return NULL; |
| 8996 | } |
| 8997 | |
| 8998 | if ((cmd->arity > 0 && cmd->arity != argc) || (argc < -cmd->arity)) { |
| 8999 | errno = EINVAL; |
| 9000 | return NULL; |
| 9001 | } |
| 9002 | |
| 9003 | getKeysResult result = GETKEYS_RESULT_INIT; |
| 9004 | getKeysFromCommand(cmd, argv, argc, &result); |
| 9005 | |
| 9006 | *num_keys = result.numkeys; |
| 9007 | if (!result.numkeys) { |
| 9008 | errno = 0; |
| 9009 | getKeysFreeResult(&result); |
| 9010 | return NULL; |
| 9011 | } |
| 9012 | |
| 9013 | if (result.keys == result.keysbuf) { |
| 9014 | /* If the result is using a stack based array, copy it. */ |
| 9015 | unsigned long int size = sizeof(int) * result.numkeys; |
| 9016 | res = zmalloc(size); |
| 9017 | memcpy(res, result.keys, size); |
| 9018 | } else { |
| 9019 | /* We return the heap based array and intentionally avoid calling |
| 9020 | * getKeysFreeResult() here, as it is the caller's responsibility |
| 9021 | * to free this array. |
| 9022 | */ |
| 9023 | res = result.keys; |
| 9024 | } |
| 9025 | |
| 9026 | return res; |
| 9027 | } |
| 9028 | |
| 9029 | /* Return the name of the command currently running */ |
| 9030 | const char *RM_GetCurrentCommandName(RedisModuleCtx *ctx) { |
nothing calls this directly
no test coverage detected