1
- 'use strict' ;
1
+ 'use strict'
2
2
3
- var commands = require ( './commands' ) ;
3
+ var commands = require ( './commands' )
4
4
5
5
/**
6
6
* Redis command list
@@ -10,15 +10,15 @@ var commands = require('./commands');
10
10
* @var {string[]}
11
11
* @public
12
12
*/
13
- exports . list = Object . keys ( commands ) ;
13
+ exports . list = Object . keys ( commands )
14
14
15
- var flags = { } ;
15
+ var flags = { }
16
16
exports . list . forEach ( function ( commandName ) {
17
17
flags [ commandName ] = commands [ commandName ] . flags . reduce ( function ( flags , flag ) {
18
- flags [ flag ] = true ;
19
- return flags ;
20
- } , { } ) ;
21
- } ) ;
18
+ flags [ flag ] = true
19
+ return flags
20
+ } , { } )
21
+ } )
22
22
/**
23
23
* Check if the command exists
24
24
*
@@ -27,8 +27,8 @@ exports.list.forEach(function (commandName) {
27
27
* @public
28
28
*/
29
29
exports . exists = function ( commandName ) {
30
- return Boolean ( commands [ commandName ] ) ;
31
- } ;
30
+ return Boolean ( commands [ commandName ] )
31
+ }
32
32
33
33
/**
34
34
* Check if the command has the flag
@@ -41,11 +41,11 @@ exports.exists = function (commandName) {
41
41
*/
42
42
exports . hasFlag = function ( commandName , flag ) {
43
43
if ( ! flags [ commandName ] ) {
44
- throw new Error ( 'Unknown command ' + commandName ) ;
44
+ throw new Error ( 'Unknown command ' + commandName )
45
45
}
46
46
47
- return Boolean ( flags [ commandName ] [ flag ] ) ;
48
- } ;
47
+ return Boolean ( flags [ commandName ] [ flag ] )
48
+ }
49
49
50
50
/**
51
51
* Get indexes of keys in the command arguments
@@ -64,91 +64,92 @@ exports.hasFlag = function (commandName, flag) {
64
64
* ```
65
65
*/
66
66
exports . getKeyIndexes = function ( commandName , args , options ) {
67
- var command = commands [ commandName ] ;
67
+ var command = commands [ commandName ]
68
68
if ( ! command ) {
69
- throw new Error ( 'Unknown command ' + commandName ) ;
69
+ throw new Error ( 'Unknown command ' + commandName )
70
70
}
71
71
72
72
if ( ! Array . isArray ( args ) ) {
73
- throw new Error ( 'Expect args to be an array' ) ;
73
+ throw new Error ( 'Expect args to be an array' )
74
74
}
75
75
76
- var keys = [ ] ;
77
- var i , keyStart , keyStop , parseExternalKey ;
76
+ var keys = [ ]
77
+ var i , keyStart , keyStop , parseExternalKey
78
78
switch ( commandName ) {
79
- case 'zunionstore' :
80
- case 'zinterstore' :
81
- keys . push ( 0 ) ;
82
- case 'eval' :
83
- case 'evalsha' :
84
- keyStop = Number ( args [ 1 ] ) + 2 ;
85
- for ( i = 2 ; i < keyStop ; i ++ ) {
86
- keys . push ( i ) ;
87
- }
88
- break ;
89
- case 'sort' :
90
- parseExternalKey = options && options . parseExternalKey ;
91
- keys . push ( 0 ) ;
92
- for ( i = 1 ; i < args . length - 1 ; i ++ ) {
93
- if ( typeof args [ i ] !== 'string' ) {
94
- continue ;
79
+ case 'zunionstore' :
80
+ case 'zinterstore' :
81
+ keys . push ( 0 )
82
+ // fall through
83
+ case 'eval' :
84
+ case 'evalsha' :
85
+ keyStop = Number ( args [ 1 ] ) + 2
86
+ for ( i = 2 ; i < keyStop ; i ++ ) {
87
+ keys . push ( i )
95
88
}
96
- var directive = args [ i ] . toUpperCase ( ) ;
97
- if ( directive === 'GET' ) {
98
- i += 1 ;
99
- if ( args [ i ] !== '#' ) {
89
+ break
90
+ case 'sort' :
91
+ parseExternalKey = options && options . parseExternalKey
92
+ keys . push ( 0 )
93
+ for ( i = 1 ; i < args . length - 1 ; i ++ ) {
94
+ if ( typeof args [ i ] !== 'string' ) {
95
+ continue
96
+ }
97
+ var directive = args [ i ] . toUpperCase ( )
98
+ if ( directive === 'GET' ) {
99
+ i += 1
100
+ if ( args [ i ] !== '#' ) {
101
+ if ( parseExternalKey ) {
102
+ keys . push ( [ i , getExternalKeyNameLength ( args [ i ] ) ] )
103
+ } else {
104
+ keys . push ( i )
105
+ }
106
+ }
107
+ } else if ( directive === 'BY' ) {
108
+ i += 1
100
109
if ( parseExternalKey ) {
101
- keys . push ( [ i , getExternalKeyNameLength ( args [ i ] ) ] ) ;
110
+ keys . push ( [ i , getExternalKeyNameLength ( args [ i ] ) ] )
102
111
} else {
103
- keys . push ( i ) ;
112
+ keys . push ( i )
104
113
}
114
+ } else if ( directive === 'STORE' ) {
115
+ i += 1
116
+ keys . push ( i )
105
117
}
106
- } else if ( directive === 'BY' ) {
107
- i += 1 ;
108
- if ( parseExternalKey ) {
109
- keys . push ( [ i , getExternalKeyNameLength ( args [ i ] ) ] ) ;
110
- } else {
111
- keys . push ( i ) ;
112
- }
113
- } else if ( directive === 'STORE' ) {
114
- i += 1 ;
115
- keys . push ( i ) ;
116
118
}
117
- }
118
- break ;
119
- case 'migrate' :
120
- if ( args [ 2 ] === '' ) {
121
- for ( i = 5 ; i < args . length - 1 ; i ++ ) {
122
- if ( args [ i ] . toUpperCase ( ) === 'KEYS' ) {
123
- for ( var j = i + 1 ; j < args . length ; j ++ ) {
124
- keys . push ( j ) ;
119
+ break
120
+ case 'migrate' :
121
+ if ( args [ 2 ] === '' ) {
122
+ for ( i = 5 ; i < args . length - 1 ; i ++ ) {
123
+ if ( args [ i ] . toUpperCase ( ) === 'KEYS' ) {
124
+ for ( var j = i + 1 ; j < args . length ; j ++ ) {
125
+ keys . push ( j )
126
+ }
127
+ break
125
128
}
126
- break ;
127
129
}
130
+ } else {
131
+ keys . push ( 2 )
128
132
}
129
- } else {
130
- keys . push ( 2 ) ;
131
- }
132
- break ;
133
- default :
133
+ break
134
+ default :
134
135
// 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 ;
138
- for ( i = keyStart ; i < keyStop ; i += command . step ) {
139
- keys . push ( i ) ;
136
+ if ( command . step > 0 ) {
137
+ keyStart = command . keyStart - 1
138
+ keyStop = command . keyStop > 0 ? command . keyStop : args . length + command . keyStop + 1
139
+ for ( i = keyStart ; i < keyStop ; i += command . step ) {
140
+ keys . push ( i )
141
+ }
140
142
}
141
- }
142
- break ;
143
+ break
143
144
}
144
145
145
- return keys ;
146
- } ;
146
+ return keys
147
+ }
147
148
148
- function getExternalKeyNameLength ( key ) {
149
+ function getExternalKeyNameLength ( key ) {
149
150
if ( typeof key !== 'string' ) {
150
- key = String ( key ) ;
151
+ key = String ( key )
151
152
}
152
- var hashPos = key . indexOf ( '->' ) ;
153
- return hashPos === - 1 ? key . length : hashPos ;
153
+ var hashPos = key . indexOf ( '->' )
154
+ return hashPos === - 1 ? key . length : hashPos
154
155
}
0 commit comments