@@ -5,85 +5,63 @@ import { expect } from "chai";
5
5
describe ( "transformer" , ( ) => {
6
6
describe ( "default transformer" , ( ) => {
7
7
describe ( "hmset" , ( ) => {
8
- it ( "should support object" , ( done ) => {
8
+ it ( "should support object" , async ( ) => {
9
9
const redis = new Redis ( ) ;
10
- redis . hmset ( "foo" , { a : 1 , b : "2" } , function ( err , result ) {
11
- expect ( result ) . to . eql ( "OK" ) ;
12
- redis . hget ( "foo" , "b" , function ( err , result ) {
13
- expect ( result ) . to . eql ( "2" ) ;
14
- done ( ) ;
15
- } ) ;
16
- } ) ;
10
+ expect ( await redis . hmset ( "foo" , { a : 1 , b : "2" } ) ) . to . eql ( "OK" ) ;
11
+ expect ( await redis . hget ( "foo" , "b" ) ) . to . eql ( "2" ) ;
17
12
} ) ;
18
- it ( "should support Map" , ( done ) => {
13
+
14
+ it ( "should support Map with string keys" , async ( ) => {
19
15
const redis = new Redis ( ) ;
20
16
const map = new Map ( ) ;
21
17
map . set ( "a" , 1 ) ;
22
18
map . set ( "b" , "2" ) ;
23
- redis . hmset ( "foo" , map , function ( err , result ) {
24
- expect ( result ) . to . eql ( "OK" ) ;
25
- redis . hget ( "foo" , "b" , function ( err , result ) {
26
- expect ( result ) . to . eql ( "2" ) ;
27
- done ( ) ;
28
- } ) ;
29
- } ) ;
19
+ map . set ( 42 , true ) ;
20
+ map . set ( Buffer . from ( "buffer" ) , "utf8" ) ;
21
+ map . set ( Buffer . from ( [ 0xff ] ) , "binary" ) ;
22
+ expect ( await redis . hmset ( "foo" , map ) ) . to . eql ( "OK" ) ;
23
+ expect ( await redis . hget ( "foo" , "a" ) ) . to . eql ( "1" ) ;
24
+ expect ( await redis . hget ( "foo" , "b" ) ) . to . eql ( "2" ) ;
25
+ expect ( await redis . hget ( "foo" , "42" ) ) . to . eql ( "true" ) ;
26
+ expect ( await redis . hget ( "foo" , "buffer" ) ) . to . eql ( "utf8" ) ;
27
+ expect ( await redis . hget ( "foo" , Buffer . from ( [ 0xff ] ) ) ) . to . eql ( "binary" ) ;
30
28
} ) ;
31
- it ( "should not affect the old way" , ( done ) => {
29
+
30
+ it ( "should not affect the old way" , async ( ) => {
32
31
const redis = new Redis ( ) ;
33
- redis . hmset ( "foo" , "a" , 1 , "b" , "2" , function ( err , result ) {
34
- expect ( result ) . to . eql ( "OK" ) ;
35
- redis . hget ( "foo" , "b" , function ( err , result ) {
36
- expect ( result ) . to . eql ( "2" ) ;
37
- done ( ) ;
38
- } ) ;
39
- } ) ;
32
+ expect ( await redis . hmset ( "foo" , "a" , 1 , "b" , "2" ) ) . to . eql ( "OK" ) ;
33
+ expect ( await redis . hget ( "foo" , "b" ) ) . to . eql ( "2" ) ;
40
34
} ) ;
41
35
} ) ;
42
36
43
37
describe ( "mset" , ( ) => {
44
- it ( "should support object" , ( done ) => {
38
+ it ( "should support object" , async ( ) => {
45
39
const redis = new Redis ( ) ;
46
- redis . mset ( { a : 1 , b : "2" } , function ( err , result ) {
47
- expect ( result ) . to . eql ( "OK" ) ;
48
- redis . mget ( "a" , "b" , function ( err , result ) {
49
- expect ( result ) . to . eql ( [ "1" , "2" ] ) ;
50
- done ( ) ;
51
- } ) ;
52
- } ) ;
40
+ expect ( await redis . mset ( { a : 1 , b : "2" } ) ) . to . eql ( "OK" ) ;
41
+ expect ( await redis . mget ( "a" , "b" ) ) . to . eql ( [ "1" , "2" ] ) ;
53
42
} ) ;
54
- it ( "should support Map" , ( done ) => {
43
+
44
+ it ( "should support Map" , async ( ) => {
55
45
const redis = new Redis ( ) ;
56
46
const map = new Map ( ) ;
57
47
map . set ( "a" , 1 ) ;
58
48
map . set ( "b" , "2" ) ;
59
- redis . mset ( map , function ( err , result ) {
60
- expect ( result ) . to . eql ( "OK" ) ;
61
- redis . mget ( "a" , "b" , function ( err , result ) {
62
- expect ( result ) . to . eql ( [ "1" , "2" ] ) ;
63
- done ( ) ;
64
- } ) ;
65
- } ) ;
49
+ expect ( await redis . mset ( map ) ) . to . eql ( "OK" ) ;
50
+ expect ( await redis . mget ( "a" , "b" ) ) . to . eql ( [ "1" , "2" ] ) ;
66
51
} ) ;
67
- it ( "should not affect the old way" , ( done ) => {
52
+
53
+ it ( "should not affect the old way" , async ( ) => {
68
54
const redis = new Redis ( ) ;
69
- redis . mset ( "a" , 1 , "b" , "2" , function ( err , result ) {
70
- expect ( result ) . to . eql ( "OK" ) ;
71
- redis . mget ( "a" , "b" , function ( err , result ) {
72
- expect ( result ) . to . eql ( [ "1" , "2" ] ) ;
73
- done ( ) ;
74
- } ) ;
75
- } ) ;
55
+ expect ( await redis . mset ( "a" , 1 , "b" , "2" ) ) . to . eql ( "OK" ) ;
56
+ expect ( await redis . mget ( "a" , "b" ) ) . to . eql ( [ "1" , "2" ] ) ;
76
57
} ) ;
77
- it ( "should work with keyPrefix option" , ( done ) => {
58
+
59
+ it ( "should work with keyPrefix option" , async ( ) => {
78
60
const redis = new Redis ( { keyPrefix : "foo:" } ) ;
79
- redis . mset ( { a : 1 , b : "2" } , function ( err , result ) {
80
- expect ( result ) . to . eql ( "OK" ) ;
81
- const otherRedis = new Redis ( ) ;
82
- otherRedis . mget ( "foo:a" , "foo:b" , function ( err , result ) {
83
- expect ( result ) . to . eql ( [ "1" , "2" ] ) ;
84
- done ( ) ;
85
- } ) ;
86
- } ) ;
61
+ expect ( await redis . mset ( { a : 1 , b : "2" } ) ) . to . eql ( "OK" ) ;
62
+
63
+ const otherRedis = new Redis ( ) ;
64
+ expect ( await otherRedis . mget ( "foo:a" , "foo:b" ) ) . to . eql ( [ "1" , "2" ] ) ;
87
65
} ) ;
88
66
} ) ;
89
67
0 commit comments