Skip to content

Commit 9335cc9

Browse files
author
Ruben Bridgewater
committed
Minor performance optimization
1 parent 8aba131 commit 9335cc9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Features
55
- Added support for `MIGRATE [...] KEYS key1, key2` (Redis >= v.3.0.6)
66
- Added build sanity check for unhandled commands with moveable keys
77
- Rebuild the commands with the newest unstable release
8+
- Improved performance of .getKeyIndexes()
89

910
Bugfix
1011

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@ exports.getKeyIndexes = function (commandName, args, options) {
131131
}
132132
break;
133133
default:
134-
keyStart = command.keyStart - 1;
135-
keyStop = command.keyStop > 0 ? command.keyStop : args.length + command.keyStop + 1;
136-
if (keyStart >= 0 && keyStop <= args.length && keyStop > keyStart && command.step > 0) {
134+
// step has to be at least one in this case, otherwise the command does not contain a key
135+
if (command.step > 0) {
136+
keyStart = command.keyStart - 1;
137+
keyStop = command.keyStop > 0 ? command.keyStop : args.length + command.keyStop + 1;
137138
for (i = keyStart; i < keyStop; i += command.step) {
138139
keys.push(i);
139140
}

0 commit comments

Comments
 (0)