@@ -10,27 +10,23 @@ t.beforeEach(done => {
10
10
11
11
fastify . register ( fastifyRedis , {
12
12
host : '127.0.0.1'
13
- } , ( err ) => {
14
- t . error ( err )
15
13
} )
16
14
17
15
fastify . ready ( err => {
18
16
t . error ( err )
19
17
20
- fastify . redis . flushdb ( ( ) => {
18
+ fastify . redis . flushall ( ( ) => {
21
19
fastify . close ( )
22
20
done ( )
23
21
} )
24
22
} )
25
23
} )
26
24
27
25
test ( 'fastify.redis should exist' , t => {
28
- t . plan ( 3 )
26
+ t . plan ( 2 )
29
27
const fastify = Fastify ( )
30
28
fastify . register ( fastifyRedis , {
31
29
host : '127.0.0.1'
32
- } , ( err ) => {
33
- t . error ( err )
34
30
} )
35
31
36
32
fastify . ready ( err => {
@@ -42,13 +38,11 @@ test('fastify.redis should exist', t => {
42
38
} )
43
39
44
40
test ( 'fastify.redis should be the redis client' , t => {
45
- t . plan ( 5 )
41
+ t . plan ( 4 )
46
42
const fastify = Fastify ( )
47
43
48
44
fastify . register ( fastifyRedis , {
49
45
host : '127.0.0.1'
50
- } , ( err ) => {
51
- t . error ( err )
52
46
} )
53
47
54
48
fastify . ready ( err => {
@@ -66,57 +60,35 @@ test('fastify.redis should be the redis client', t => {
66
60
} )
67
61
} )
68
62
69
- test ( 'fastify.redis should exist when use the custom redis driver' , t => {
70
- t . plan ( 3 )
71
- const fastify = Fastify ( )
72
-
73
- fastify . register ( fastifyRedis , {
74
- driver : require ( 'ioredis' ) ,
75
- host : '127.0.0.1'
76
- } , ( err ) => {
77
- t . error ( err )
78
- } )
79
-
80
- fastify . ready ( err => {
81
- t . error ( err )
82
- t . ok ( fastify . redis )
83
-
84
- fastify . close ( )
85
- } )
86
- } )
87
-
88
- test ( 'fastify.redis should be the redis client when use the custom redis driver' , t => {
89
- t . plan ( 5 )
63
+ test ( 'promises support' , t => {
64
+ t . plan ( 2 )
90
65
const fastify = Fastify ( )
91
66
92
67
fastify . register ( fastifyRedis , {
93
- driver : require ( 'ioredis' ) ,
94
68
host : '127.0.0.1'
95
- } , ( err ) => {
96
- t . error ( err )
97
69
} )
98
70
99
71
fastify . ready ( err => {
100
72
t . error ( err )
101
73
102
- fastify . redis . set ( 'key' , 'value' , err => {
103
- t . error ( err )
104
- fastify . redis . get ( 'key' , ( err , val ) => {
105
- t . error ( err )
74
+ fastify . redis . set ( 'key' , 'value' )
75
+ . then ( ( ) => {
76
+ return fastify . redis . get ( 'key' )
77
+ } )
78
+ . then ( val => {
106
79
t . equal ( val , 'value' )
107
-
108
80
fastify . close ( )
109
81
} )
110
- } )
82
+ . catch ( err => t . fail ( err ) )
111
83
} )
112
84
} )
113
85
114
- test ( 'fastify.redis should be a singleton ' , t => {
86
+ test ( 'custom client ' , t => {
115
87
t . plan ( 5 )
116
88
const fastify = Fastify ( )
117
- const redis = require ( 'redis' ) . createClient ( { host : 'localhost' , port : 6379 } )
89
+ const redis = require ( 'redis' ) . createClient ( { host : 'localhost' , port : 6379 } )
118
90
119
- fastify . register ( fastifyRedis , { client : redis } )
91
+ fastify . register ( fastifyRedis , { client : redis } )
120
92
121
93
fastify . ready ( err => {
122
94
t . error ( err )
0 commit comments