1- 'use strict' ;
1+ 'use strict'
22
3- var commands = require ( './commands' ) ;
3+ var commands = require ( './commands' )
44
55/**
66 * Redis command list
@@ -10,15 +10,15 @@ var commands = require('./commands');
1010 * @var {string[]}
1111 * @public
1212 */
13- exports . list = Object . keys ( commands ) ;
13+ exports . list = Object . keys ( commands )
1414
15- var flags = { } ;
15+ var flags = { }
1616exports . list . forEach ( function ( commandName ) {
1717 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+ } )
2222/**
2323 * Check if the command exists
2424 *
@@ -27,8 +27,8 @@ exports.list.forEach(function (commandName) {
2727 * @public
2828 */
2929exports . exists = function ( commandName ) {
30- return Boolean ( commands [ commandName ] ) ;
31- } ;
30+ return Boolean ( commands [ commandName ] )
31+ }
3232
3333/**
3434 * Check if the command has the flag
@@ -41,11 +41,11 @@ exports.exists = function (commandName) {
4141 */
4242exports . hasFlag = function ( commandName , flag ) {
4343 if ( ! flags [ commandName ] ) {
44- throw new Error ( 'Unknown command ' + commandName ) ;
44+ throw new Error ( 'Unknown command ' + commandName )
4545 }
4646
47- return Boolean ( flags [ commandName ] [ flag ] ) ;
48- } ;
47+ return Boolean ( flags [ commandName ] [ flag ] )
48+ }
4949
5050/**
5151 * Get indexes of keys in the command arguments
@@ -64,91 +64,92 @@ exports.hasFlag = function (commandName, flag) {
6464 * ```
6565 */
6666exports . getKeyIndexes = function ( commandName , args , options ) {
67- var command = commands [ commandName ] ;
67+ var command = commands [ commandName ]
6868 if ( ! command ) {
69- throw new Error ( 'Unknown command ' + commandName ) ;
69+ throw new Error ( 'Unknown command ' + commandName )
7070 }
7171
7272 if ( ! Array . isArray ( args ) ) {
73- throw new Error ( 'Expect args to be an array' ) ;
73+ throw new Error ( 'Expect args to be an array' )
7474 }
7575
76- var keys = [ ] ;
77- var i , keyStart , keyStop , parseExternalKey ;
76+ var keys = [ ]
77+ var i , keyStart , keyStop , parseExternalKey
7878 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 )
9588 }
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
100109 if ( parseExternalKey ) {
101- keys . push ( [ i , getExternalKeyNameLength ( args [ i ] ) ] ) ;
110+ keys . push ( [ i , getExternalKeyNameLength ( args [ i ] ) ] )
102111 } else {
103- keys . push ( i ) ;
112+ keys . push ( i )
104113 }
114+ } else if ( directive === 'STORE' ) {
115+ i += 1
116+ keys . push ( i )
105117 }
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 ) ;
116118 }
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
125128 }
126- break ;
127129 }
130+ } else {
131+ keys . push ( 2 )
128132 }
129- } else {
130- keys . push ( 2 ) ;
131- }
132- break ;
133- default :
133+ break
134+ default :
134135 // 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+ }
140142 }
141- }
142- break ;
143+ break
143144 }
144145
145- return keys ;
146- } ;
146+ return keys
147+ }
147148
148- function getExternalKeyNameLength ( key ) {
149+ function getExternalKeyNameLength ( key ) {
149150 if ( typeof key !== 'string' ) {
150- key = String ( key ) ;
151+ key = String ( key )
151152 }
152- var hashPos = key . indexOf ( '->' ) ;
153- return hashPos === - 1 ? key . length : hashPos ;
153+ var hashPos = key . indexOf ( '->' )
154+ return hashPos === - 1 ? key . length : hashPos
154155}
0 commit comments