File tree Expand file tree Collapse file tree 2 files changed +23
-16
lines changed
packages/client/lib/commands Expand file tree Collapse file tree 2 files changed +23
-16
lines changed Original file line number Diff line number Diff line change @@ -4,13 +4,20 @@ import { transformArguments } from './SET';
4
4
5
5
describe ( 'SET' , ( ) => {
6
6
describe ( 'transformArguments' , ( ) => {
7
- it ( 'simple ' , ( ) => {
7
+ it ( 'string ' , ( ) => {
8
8
assert . deepEqual (
9
9
transformArguments ( 'key' , 'value' ) ,
10
10
[ 'SET' , 'key' , 'value' ]
11
11
) ;
12
12
} ) ;
13
13
14
+ it ( 'number' , ( ) => {
15
+ assert . deepEqual (
16
+ transformArguments ( 'key' , 1 ) ,
17
+ [ 'SET' , 'key' , '1' ]
18
+ ) ;
19
+ } ) ;
20
+
14
21
describe ( 'TTL' , ( ) => {
15
22
it ( 'with EX' , ( ) => {
16
23
assert . deepEqual (
Original file line number Diff line number Diff line change @@ -24,32 +24,32 @@ interface SetCommonOptions {
24
24
25
25
type SetOptions = SetTTL & SetGuards & SetCommonOptions ;
26
26
27
- export function transformArguments ( key : string | Buffer , value : string | Buffer , options ?: SetOptions ) : RedisCommandArguments {
28
- const args = [ 'SET' , key , value ] ;
29
-
30
- if ( ! options ) {
31
- return args ;
32
- }
33
-
34
- if ( options . EX ) {
27
+ export function transformArguments ( key : string | Buffer , value : string | number | Buffer , options ?: SetOptions ) : RedisCommandArguments {
28
+ const args = [
29
+ 'SET' ,
30
+ key ,
31
+ typeof value === 'number' ? value . toString ( ) : value
32
+ ] ;
33
+
34
+ if ( options ? .EX ) {
35
35
args . push ( 'EX' , options . EX . toString ( ) ) ;
36
- } else if ( options . PX ) {
36
+ } else if ( options ? .PX ) {
37
37
args . push ( 'PX' , options . PX . toString ( ) ) ;
38
- } else if ( options . EXAT ) {
38
+ } else if ( options ? .EXAT ) {
39
39
args . push ( 'EXAT' , options . EXAT . toString ( ) ) ;
40
- } else if ( options . PXAT ) {
40
+ } else if ( options ? .PXAT ) {
41
41
args . push ( 'PXAT' , options . PXAT . toString ( ) ) ;
42
- } else if ( options . KEEPTTL ) {
42
+ } else if ( options ? .KEEPTTL ) {
43
43
args . push ( 'KEEPTTL' ) ;
44
44
}
45
45
46
- if ( options . NX ) {
46
+ if ( options ? .NX ) {
47
47
args . push ( 'NX' ) ;
48
- } else if ( options . XX ) {
48
+ } else if ( options ? .XX ) {
49
49
args . push ( 'XX' ) ;
50
50
}
51
51
52
- if ( options . GET ) {
52
+ if ( options ? .GET ) {
53
53
args . push ( 'GET' ) ;
54
54
}
55
55
You can’t perform that action at this time.
0 commit comments