@@ -17,11 +17,7 @@ var changeFunctionName = (function () {
1717 }
1818} ( ) ) ;
1919
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 ) {
2521 // Some rare Redis commands use special characters in their command name
2622 // Convert those to a underscore to prevent using invalid function names
2723 var commandName = command . replace ( / (?: ^ ( [ 0 - 9 ] ) | [ ^ a - z A - Z 0 - 9 _ $ ] ) / g, '_$1' ) ;
@@ -61,8 +57,12 @@ commands.list.forEach(function (command) {
6157 }
6258 return this . internal_send_command ( new Command ( command , arr , callback ) ) ;
6359 } ;
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+ }
6464 if ( changeFunctionName ) {
65- Object . defineProperty ( RedisClient . prototype [ command ] , 'name' , {
65+ Object . defineProperty ( RedisClient . prototype [ commandName ] , 'name' , {
6666 value : commandName
6767 } ) ;
6868 }
@@ -104,10 +104,18 @@ commands.list.forEach(function (command) {
104104 this . queue . push ( new Command ( command , arr , callback ) ) ;
105105 return this ;
106106 } ;
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+ }
107111 if ( changeFunctionName ) {
108- Object . defineProperty ( Multi . prototype [ command ] , 'name' , {
112+ Object . defineProperty ( Multi . prototype [ commandName ] , 'name' , {
109113 value : commandName
110114 } ) ;
111115 }
112116 }
113- } ) ;
117+ } ;
118+
119+ commands . list . forEach ( addCommand ) ;
120+
121+ module . exports = addCommand ;
0 commit comments