@@ -17,11 +17,7 @@ var changeFunctionName = (function () {
17
17
}
18
18
} ( ) ) ;
19
19
20
- // TODO: Rewrite this including the invidual commands into a Commands class
21
- // that provided a functionality to add new commands to the client
22
-
23
- commands . list . forEach ( function ( command ) {
24
-
20
+ var addCommand = function ( command ) {
25
21
// Some rare Redis commands use special characters in their command name
26
22
// Convert those to a underscore to prevent using invalid function names
27
23
var commandName = command . replace ( / (?: ^ ( [ 0 - 9 ] ) | [ ^ a - z A - Z 0 - 9 _ $ ] ) / g, '_$1' ) ;
@@ -61,8 +57,12 @@ commands.list.forEach(function (command) {
61
57
}
62
58
return this . internal_send_command ( new Command ( command , arr , callback ) ) ;
63
59
} ;
60
+ //alias commands with illegal function names (e.g. NR.RUN becomes NR_RUN and nr_run)
61
+ if ( commandName !== command ) {
62
+ RedisClient . prototype [ commandName . toUpperCase ( ) ] = RedisClient . prototype [ commandName ] = RedisClient . prototype [ command ] ;
63
+ }
64
64
if ( changeFunctionName ) {
65
- Object . defineProperty ( RedisClient . prototype [ command ] , 'name' , {
65
+ Object . defineProperty ( RedisClient . prototype [ commandName ] , 'name' , {
66
66
value : commandName
67
67
} ) ;
68
68
}
@@ -104,10 +104,18 @@ commands.list.forEach(function (command) {
104
104
this . queue . push ( new Command ( command , arr , callback ) ) ;
105
105
return this ;
106
106
} ;
107
+ //alias commands with illegal function names (e.g. NR.RUN becomes NR_RUN and nr_run)
108
+ if ( commandName !== command ) {
109
+ Multi . prototype [ commandName . toUpperCase ( ) ] = Multi . prototype [ commandName ] = Multi . prototype [ command ] ;
110
+ }
107
111
if ( changeFunctionName ) {
108
- Object . defineProperty ( Multi . prototype [ command ] , 'name' , {
112
+ Object . defineProperty ( Multi . prototype [ commandName ] , 'name' , {
109
113
value : commandName
110
114
} ) ;
111
115
}
112
116
}
113
- } ) ;
117
+ } ;
118
+
119
+ commands . list . forEach ( addCommand ) ;
120
+
121
+ module . exports = addCommand ;
0 commit comments