Skip to content

Commit 9b0ba69

Browse files
author
Ruben Bridgewater
committed
Add sanity check for unhandled commands with movable keys
1 parent 935a844 commit 9b0ba69

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Features
44

5+
- Added build sanity check for unhandled commands with moveable keys
56
- Rebuild the commands with the newest unstable release
67

78
Bugfix

tools/build.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@ var fs = require('fs');
22
var path = require('path');
33
var stringify = require('json-stable-stringify');
44
var commandPath = path.join(__dirname, '..', 'commands.json');
5+
var redisCommands = require('../');
56

67
var Redis = require('ioredis');
78
var redis = new Redis(process.env.REDIS_URI);
89

9-
redis.command(function (err, res) {
10+
redis.command().then(function (res) {
1011
redis.disconnect();
1112

12-
if (err) {
13-
throw err;
14-
}
13+
// Find all special handled cases
14+
var movableKeys = String(redisCommands.getKeyIndexes).match(/case '[a-z-]+':/g).map(function (entry) {
15+
return entry.replace(/^case \'|\':$/g, '');
16+
});
1517

1618
var commands = res.reduce(function (prev, current) {
19+
var currentCommandPos = movableKeys.indexOf(current[0]);
20+
if (currentCommandPos !== -1 && current[2].indexOf('movablekeys') !== -1) {
21+
movableKeys.splice(currentCommandPos, 1);
22+
}
1723
// https://github.com/antirez/redis/issues/2598
1824
if (current[0] === 'brpop' && current[4] === 1) {
1925
current[4] = -2;
@@ -44,6 +50,10 @@ redis.command(function (err, res) {
4450
}
4551
}
4652

53+
if (movableKeys.length !== 0) {
54+
throw new Error('Not all commands (\'' + movableKeys.join('\', \'') + '\') with the "movablekeys" flag are handled in the code');
55+
}
56+
4757
// Use json-stable-stringify instead fo JSON.stringify
4858
// for easier diffing
4959
var content = stringify(commands, { space: ' ' });

0 commit comments

Comments
 (0)