333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var fs = require('fs')
var path = require('path')
var stringify = require('safe-stable-stringify')
var commandPath = path.join(__dirname, '..', 'commands.json')
var redisCommands = require('../')
 
var Redis = require('ioredis')
var redis = new Redis(process.env.REDIS_URI)
 
redis.command().then(function (res) {
  redis.disconnect()
 
  // Find all special handled cases
  var movableKeys = String(redisCommands.getKeyIndexes).match(/case '[a-z-]+':/g).map(function (entry) {
    return entry.replace(/^case '|':$/g, '')
  })
 
  var commands = res.reduce(function (prev, current) {
    var currentCommandPos = movableKeys.indexOf(current[0])
    if (currentCommandPos !== -1 && current[2].indexOf('movablekeys') !== -1) {
      movableKeys.splice(currentCommandPos, 1)
    }
    // https://github.com/antirez/redis/issues/2598
    if (current[0] === 'brpop' && current[4] === 1) {
      current[4] = -2
    }
    prev[current[0]] = {
      arity: current[1] || 1, // https://github.com/antirez/redis/pull/2986
      flags: current[2],
      keyStart: current[3],
      keyStop: current[4],
      step: current[5]
    }
    return prev
  }, {})
 
  // Future proof. Redis might implement this at some point
  // https://github.com/antirez/redis/pull/2982
  if (!commands.quit) {
    commands.quit = {
      arity: 1,
      flags: [
        'loading',
        'stale',
        'readonly'
      ],
      keyStart: 0,
      keyStop: 0,
      step: 0
    }
  }
 
  if (movableKeys.length !== 0) {
    throw new Error('Not all commands (\'' + movableKeys.join('\', \'') + '\') with the "movablekeys" flag are handled in the code')
  }
 
  // Use safe-stable-stringify instead fo JSON.stringify
  // for easier diffing
  var content = stringify(commands, null, '  ')
 
  fs.writeFileSync(commandPath, content)
})