diff options
author | guybe7 <guy.benoish@redislabs.com> | 2022-01-30 11:00:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-30 12:00:03 +0200 |
commit | eedec155acdd0ead3536edf6988e250a1a9fcb3e (patch) | |
tree | 5bd57919652dfb4bcfe387cacd89f5952063f2a0 /src/db.c | |
parent | be0d2933545354f4868f8e4807a11f8e79c03736 (diff) | |
download | redis-eedec155acdd0ead3536edf6988e250a1a9fcb3e.tar.gz |
Add key-specs notes (#10193)
Add optional `notes` to keyspecs.
Other changes:
1. Remove the "incomplete" flag from SORT and SORT_RO: it is misleading since "incomplete" means "this spec may not return all the keys it describes" but SORT and SORT_RO's specs (except the input key) do not return any keys at all.
So basically:
If a spec's begin_search is "unknown" you should not use it at all, you must use COMMAND KEYS;
if a spec itself is "incomplete", you can use it to get a partial list of keys, but if you want all of them you must use COMMAND GETKEYS;
otherwise, the spec will return all the keys
2. `getKeysUsingKeySpecs` handles incomplete specs internally
Diffstat (limited to 'src/db.c')
-rw-r--r-- | src/db.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -1704,7 +1704,7 @@ int getKeysUsingKeySpecs(struct redisCommand *cmd, robj **argv, int argc, int se keySpec *spec = cmd->key_specs + j; serverAssert(spec->begin_search_type != KSPEC_BS_INVALID); /* Skip specs that represent channels instead of keys */ - if (spec->flags & (CMD_KEY_CHANNEL) && !(search_flags & GET_KEYSPEC_INCLUDE_CHANNELS)) { + if ((spec->flags & CMD_KEY_CHANNEL) && !(search_flags & GET_KEYSPEC_INCLUDE_CHANNELS)) { continue; } @@ -1788,6 +1788,12 @@ int getKeysUsingKeySpecs(struct redisCommand *cmd, robj **argv, int argc, int se keys[k++].flags = spec->flags; } + /* Handle incomplete specs (only after we added the current spec + * to `keys`, just in case GET_KEYSPEC_RETURN_PARTIAL was given) */ + if (spec->flags & CMD_KEY_INCOMPLETE) { + goto invalid_spec; + } + /* Done with this spec */ continue; @@ -1824,7 +1830,7 @@ int getKeysFromCommandWithSpecs(struct redisCommand *cmd, robj **argv, int argc, if (cmd->flags & CMD_MODULE_GETKEYS) { return moduleGetCommandKeysViaAPI(cmd,argv,argc,result); } else { - if (!(getAllKeySpecsFlags(cmd, 0) & (CMD_KEY_INCOMPLETE|CMD_KEY_VARIABLE_FLAGS))) { + if (!(getAllKeySpecsFlags(cmd, 0) & CMD_KEY_VARIABLE_FLAGS)) { int ret = getKeysUsingKeySpecs(cmd,argv,argc,search_flags,result); if (ret >= 0) return ret; |