MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / getKeysUsingCommandTable

Function getKeysUsingCommandTable

src/db.cpp:2151–2185  ·  view source on GitHub ↗

The base case is to use the keys position as given in the command table * (firstkey, lastkey, step). */

Source from the content-addressed store, hash-verified

2149/* The base case is to use the keys position as given in the command table
2150 * (firstkey, lastkey, step). */
2151int getKeysUsingCommandTable(struct redisCommand *cmd,robj **argv, int argc, getKeysResult *result) {
2152 int j, i = 0, last, *keys;
2153 UNUSED(argv);
2154
2155 if (cmd->firstkey == 0) {
2156 result->numkeys = 0;
2157 return 0;
2158 }
2159
2160 last = cmd->lastkey;
2161 if (last < 0) last = argc+last;
2162
2163 int count = ((last - cmd->firstkey)+1);
2164 keys = getKeysPrepareResult(result, count);
2165
2166 for (j = cmd->firstkey; j <= last; j += cmd->keystep) {
2167 if (j >= argc) {
2168 /* Modules commands, and standard commands with a not fixed number
2169 * of arguments (negative arity parameter) do not have dispatch
2170 * time arity checks, so we need to handle the case where the user
2171 * passed an invalid number of arguments here. In this case we
2172 * return no keys and expect the command implementation to report
2173 * an arity or syntax error. */
2174 if (cmd->flags & CMD_MODULE || cmd->arity < 0) {
2175 result->numkeys = 0;
2176 return 0;
2177 } else {
2178 serverPanic("KeyDB built-in command declared keys positions not matching the arity requirements.");
2179 }
2180 }
2181 keys[i++] = j;
2182 }
2183 result->numkeys = i;
2184 return i;
2185}
2186
2187/* Return all the arguments that are keys in the command passed via argc / argv.
2188 *

Callers 1

getKeysFromCommandFunction · 0.85

Calls 1

getKeysPrepareResultFunction · 0.85

Tested by

no test coverage detected