Skip to content

Commit

Permalink
feat: update commands to Redis 7.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jun 25, 2022
1 parent 12b9e11 commit 92f0539
Show file tree
Hide file tree
Showing 6 changed files with 477 additions and 11,562 deletions.
23 changes: 9 additions & 14 deletions lib/commands.json
Expand Up @@ -75,8 +75,7 @@
"arity": -2,
"flags": [
"write",
"denyoom",
"movablekeys"
"denyoom"
],
"keyStart": 1,
"keyStop": 1,
Expand Down Expand Up @@ -334,7 +333,6 @@
"noscript",
"stale",
"skip_monitor",
"may_replicate",
"no_mandatory_keys",
"movablekeys"
],
Expand All @@ -345,6 +343,7 @@
"eval_ro": {
"arity": -3,
"flags": [
"readonly",
"noscript",
"stale",
"skip_monitor",
Expand All @@ -361,7 +360,6 @@
"noscript",
"stale",
"skip_monitor",
"may_replicate",
"no_mandatory_keys",
"movablekeys"
],
Expand All @@ -372,6 +370,7 @@
"evalsha_ro": {
"arity": -3,
"flags": [
"readonly",
"noscript",
"stale",
"skip_monitor",
Expand Down Expand Up @@ -451,7 +450,6 @@
"noscript",
"stale",
"skip_monitor",
"may_replicate",
"no_mandatory_keys",
"movablekeys"
],
Expand All @@ -462,6 +460,7 @@
"fcall_ro": {
"arity": -3,
"flags": [
"readonly",
"noscript",
"stale",
"skip_monitor",
Expand Down Expand Up @@ -1193,15 +1192,14 @@
"pfcount": {
"arity": -2,
"flags": [
"readonly",
"may_replicate"
"readonly"
],
"keyStart": 1,
"keyStop": -1,
"step": 1
},
"pfdebug": {
"arity": -3,
"arity": 3,
"flags": [
"write",
"denyoom",
Expand Down Expand Up @@ -1289,8 +1287,7 @@
"pubsub",
"loading",
"stale",
"fast",
"may_replicate"
"fast"
],
"keyStart": 0,
"keyStop": 0,
Expand Down Expand Up @@ -1576,8 +1573,7 @@
"arity": -3,
"flags": [
"write",
"denyoom",
"movablekeys"
"denyoom"
],
"keyStart": 1,
"keyStop": 1,
Expand Down Expand Up @@ -1762,8 +1758,7 @@
"pubsub",
"loading",
"stale",
"fast",
"may_replicate"
"fast"
],
"keyStart": 1,
"keyStop": 1,
Expand Down
61 changes: 55 additions & 6 deletions lib/index.ts
Expand Up @@ -65,23 +65,72 @@ export function getKeyIndexes(
const keys = [];
const parseExternalKey = Boolean(options && options.parseExternalKey);

const takeDynamicKeys = (args: unknown[], startIndex: number) => {
const keys: number[] = [];
const keyStop = Number(args[startIndex]);
for (let i = 0; i < keyStop; i++) {
keys.push(i + startIndex + 1);
}
return keys;
};

const takeKeyAfterToken = (
args: unknown[],
startIndex: number,
token: string
) => {
for (let i = startIndex; i < args.length - 1; i += 1) {
if (String(args[i]).toLowerCase() === token.toLowerCase()) {
return i + 1;
}
}
return null;
};

switch (commandName) {
case "zunionstore":
case "zinterstore":
keys.push(0);
// fall through
case "zdiffstore":
keys.push(0, ...takeDynamicKeys(args, 1));
break;
case "eval":
case "evalsha":
case "eval_ro":
case "evalsha_ro":
case "fcall":
case "fcall_ro":
const keyStop = Number(args[1]) + 2;
for (let i = 2; i < keyStop; i++) {
keys.push(i);
}
case "blmpop":
case "bzmpop":
keys.push(...takeDynamicKeys(args, 1));
break;
case "sintercard":
case "lmpop":
case "zunion":
case "zinter":
case "zmpop":
case "zintercard":
case "zdiff": {
keys.push(...takeDynamicKeys(args, 0));
break;
}
case "georadius": {
keys.push(0);
const storeKey = takeKeyAfterToken(args, 5, "STORE");
if (storeKey) keys.push(storeKey);
const distKey = takeKeyAfterToken(args, 5, "STOREDIST");
if (distKey) keys.push(distKey);
break;
}
case "georadiusbymember": {
keys.push(0);
const storeKey = takeKeyAfterToken(args, 4, "STORE");
if (storeKey) keys.push(storeKey);
const distKey = takeKeyAfterToken(args, 4, "STOREDIST");
if (distKey) keys.push(distKey);
break;
}
case "sort":
case "sort_ro":
keys.push(0);
for (let i = 1; i < args.length - 1; i++) {
let arg = args[i];
Expand Down

0 comments on commit 92f0539

Please sign in to comment.