1414 * limitations under the License.
1515 */
1616
17+ /* eslint-disable max-lines */
18+
1719import * as C from './Common' ;
1820import * as U from './Utils' ;
1921import * as E from './Errors' ;
@@ -77,7 +79,7 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
7779 } ,
7880 process ( data : Buffer | string ) : string {
7981
80- return data instanceof Buffer ? data . toString ( ) : data ;
82+ return data instanceof Buffer ? data . toString ( ) : data as string ;
8183 }
8284 } ,
8385
@@ -146,61 +148,59 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
146148 * @see https://redis.io/docs/latest/commands/incr
147149 */
148150 'incr' : {
149- prepare ( key : string , step : number ) : IPrepareResult {
151+ prepare ( key : string , step : number = 1 ) : IPrepareResult {
150152
151153 return {
152154 'cmd' : 'INCRBY' ,
153- 'args' : [ key , step || 1 ]
155+ 'args' : [ key , step ]
154156 } ;
155- }
157+ } ,
158+ // process: parseInt, // always returning integer
156159 } ,
157160
158161 /**
159162 * Command: incrByFloat
160163 * @see https://redis.io/docs/latest/commands/incrbyfloat
161164 */
162165 'incrByFloat' : {
163- prepare ( key : string , step : number ) : IPrepareResult {
166+ prepare ( key : string , step : number = 1 ) : IPrepareResult {
164167
165168 return {
166169 'cmd' : 'INCRBYFLOAT' ,
167170 'args' : [ key , step ]
168171 } ;
169172 } ,
170- process ( data : Buffer | string ) : number {
171- return parseFloat ( data as string ) ;
172- }
173+ process : parseFloat ,
173174 } ,
174175
175176 /**
176177 * Command: decr
177178 * @see https://redis.io/docs/latest/commands/decr
178179 */
179180 'decr' : {
180- prepare ( key : string , step : number ) : IPrepareResult {
181+ prepare ( key : string , step : number = 1 ) : IPrepareResult {
181182
182183 return {
183184 'cmd' : 'DECRBY' ,
184185 'args' : [ key , step ]
185186 } ;
186- }
187+ } ,
188+ // process: parseInt, // always returning integer
187189 } ,
188190
189191 /**
190192 * Command: incrByFloat
191193 * @see https://redis.io/docs/latest/commands/incrbyfloat
192194 */
193195 'decrByFloat' : {
194- prepare ( key : string , step : number ) : IPrepareResult {
196+ prepare ( key : string , step : number = 1 ) : IPrepareResult {
195197
196198 return {
197199 'cmd' : 'INCRBYFLOAT' ,
198200 'args' : [ key , - step ]
199201 } ;
200202 } ,
201- process ( data : string | Buffer ) : number {
202- return parseFloat ( data as string ) ;
203- }
203+ process : parseFloat ,
204204 } ,
205205
206206 /**
@@ -987,7 +987,7 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
987987 'mSet' : {
988988 prepare ( kv : Record < string , string | Buffer > ) : IPrepareResult {
989989
990- const args : any [ ] = [ ] ;
990+ const args : Array < string | Buffer > = [ ] ;
991991
992992 for ( const k in kv ) {
993993
@@ -1010,7 +1010,7 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
10101010 'mSetNX' : {
10111011 prepare ( kv : Record < string , string | Buffer > ) : IPrepareResult {
10121012
1013- const args : any [ ] = [ ] ;
1013+ const args : Array < string | Buffer > = [ ] ;
10141014
10151015 for ( const k in kv ) {
10161016
@@ -1031,37 +1031,49 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
10311031 * @see https://redis.io/docs/latest/commands/hincrby
10321032 */
10331033 'hIncr' : {
1034- prepare : createDefaultPreparer ( 'HINCRBY' )
1034+ prepare ( key : string , field : string , step : number = 1 ) : IPrepareResult {
1035+ return {
1036+ cmd : 'HINCRBY' ,
1037+ args : [ key , field , step ]
1038+ } ;
1039+ } ,
1040+ // process: parseInt, // always returning integer
10351041 } ,
10361042
10371043 /**
10381044 * Command: hIncrByFloat
10391045 * @see https://redis.io/docs/latest/commands/hincrbyfloat
10401046 */
10411047 'hIncrByFloat' : {
1042- prepare : createDefaultPreparer ( 'HINCRBYFLOAT' ) ,
1043- process : parseFloat
1048+ prepare ( key : string , field : string , step : number = 1 ) : IPrepareResult {
1049+ return {
1050+ cmd : 'HINCRBYFLOAT' ,
1051+ args : [ key , field , step ]
1052+ } ;
1053+ } ,
1054+ process : parseFloat ,
10441055 } ,
10451056
10461057 /**
10471058 * Command: hIncr
10481059 * @see https://redis.io/docs/latest/commands/hincrby
10491060 */
10501061 'hDecr' : {
1051- prepare ( key : string , field : string , step : number ) : IPrepareResult {
1062+ prepare ( key : string , field : string , step : number = 1 ) : IPrepareResult {
10521063 return {
10531064 cmd : 'HINCRBY' ,
1054- args : [ key , field , - ( step || 1 ) ]
1065+ args : [ key , field , - step ]
10551066 } ;
1056- }
1067+ } ,
1068+ // process: parseInt, // always returning integer
10571069 } ,
10581070
10591071 /**
10601072 * Command: hIncrByFloat
10611073 * @see https://redis.io/docs/latest/commands/hincrbyfloat
10621074 */
10631075 'hDecrByFloat' : {
1064- prepare ( key : string , field : string , step : number ) : IPrepareResult {
1076+ prepare ( key : string , field : string , step : number = 1 ) : IPrepareResult {
10651077 return {
10661078 cmd : 'HINCRBYFLOAT' ,
10671079 args : [ key , field , - step ]
0 commit comments