1
+ 'use strict' ;
2
+
3
+ var assert = require ( "assert" ) ;
4
+ var config = require ( "./lib/config" ) ;
5
+ var helper = require ( './helper' ) ;
6
+ var redis = config . redis ;
7
+
8
+ describe ( "return_buffers" , function ( ) {
9
+
10
+ helper . allTests ( function ( parser , ip ) {
11
+
12
+ describe ( "using " + parser + " and " + ip , function ( ) {
13
+ var client ;
14
+ var args = config . configureClient ( parser , ip , {
15
+ return_buffers : true ,
16
+ detect_buffers : true
17
+ } ) ;
18
+
19
+ beforeEach ( function ( done ) {
20
+ client = redis . createClient . apply ( redis . createClient , args ) ;
21
+ if ( args [ 2 ] . detect_buffers ) {
22
+ args [ 2 ] . detect_buffers = false ;
23
+ }
24
+ client . once ( "error" , done ) ;
25
+ client . once ( "connect" , function ( ) {
26
+ client . flushdb ( function ( err ) {
27
+ client . hmset ( "hash key 2" , "key 1" , "val 1" , "key 2" , "val 2" ) ;
28
+ client . set ( "string key 1" , "string value" ) ;
29
+ return done ( err ) ;
30
+ } ) ;
31
+ } ) ;
32
+ } ) ;
33
+
34
+ describe ( 'get' , function ( ) {
35
+ describe ( 'first argument is a string' , function ( ) {
36
+ it ( 'returns a buffer' , function ( done ) {
37
+ client . get ( "string key 1" , function ( err , reply ) {
38
+ assert . strictEqual ( true , Buffer . isBuffer ( reply ) ) ;
39
+ assert . strictEqual ( "<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>" , reply . inspect ( ) ) ;
40
+ return done ( err ) ;
41
+ } ) ;
42
+ } ) ;
43
+
44
+ it ( 'returns a bufffer when executed as part of transaction' , function ( done ) {
45
+ client . multi ( ) . get ( "string key 1" ) . exec ( function ( err , reply ) {
46
+ assert . strictEqual ( 1 , reply . length ) ;
47
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 0 ] ) ) ;
48
+ assert . strictEqual ( "<Buffer 73 74 72 69 6e 67 20 76 61 6c 75 65>" , reply [ 0 ] . inspect ( ) ) ;
49
+ return done ( err ) ;
50
+ } ) ;
51
+ } ) ;
52
+ } ) ;
53
+ } ) ;
54
+
55
+ describe ( 'multi.hget' , function ( ) {
56
+ it ( 'returns buffers' , function ( done ) {
57
+ client . multi ( )
58
+ . hget ( "hash key 2" , "key 1" )
59
+ . hget ( new Buffer ( "hash key 2" ) , "key 1" )
60
+ . hget ( "hash key 2" , new Buffer ( "key 2" ) )
61
+ . hget ( "hash key 2" , "key 2" )
62
+ . exec ( function ( err , reply ) {
63
+ assert . strictEqual ( true , Array . isArray ( reply ) ) ;
64
+ assert . strictEqual ( 4 , reply . length ) ;
65
+ assert . strictEqual ( "<Buffer 76 61 6c 20 31>" , reply [ 0 ] . inspect ( ) ) ;
66
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 1 ] ) ) ;
67
+ assert . strictEqual ( "<Buffer 76 61 6c 20 31>" , reply [ 1 ] . inspect ( ) ) ;
68
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 2 ] ) ) ;
69
+ assert . strictEqual ( "<Buffer 76 61 6c 20 32>" , reply [ 2 ] . inspect ( ) ) ;
70
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 3 ] ) ) ;
71
+ assert . strictEqual ( "<Buffer 76 61 6c 20 32>" , reply [ 3 ] . inspect ( ) ) ;
72
+ return done ( err ) ;
73
+ } ) ;
74
+ } ) ;
75
+ } ) ;
76
+
77
+ describe ( 'batch.hget' , function ( ) {
78
+ it ( 'returns buffers' , function ( done ) {
79
+ client . batch ( )
80
+ . hget ( "hash key 2" , "key 1" )
81
+ . hget ( new Buffer ( "hash key 2" ) , "key 1" )
82
+ . hget ( "hash key 2" , new Buffer ( "key 2" ) )
83
+ . hget ( "hash key 2" , "key 2" )
84
+ . exec ( function ( err , reply ) {
85
+ assert . strictEqual ( true , Array . isArray ( reply ) ) ;
86
+ assert . strictEqual ( 4 , reply . length ) ;
87
+ assert . strictEqual ( "<Buffer 76 61 6c 20 31>" , reply [ 0 ] . inspect ( ) ) ;
88
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 1 ] ) ) ;
89
+ assert . strictEqual ( "<Buffer 76 61 6c 20 31>" , reply [ 1 ] . inspect ( ) ) ;
90
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 2 ] ) ) ;
91
+ assert . strictEqual ( "<Buffer 76 61 6c 20 32>" , reply [ 2 ] . inspect ( ) ) ;
92
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 3 ] ) ) ;
93
+ assert . strictEqual ( "<Buffer 76 61 6c 20 32>" , reply [ 3 ] . inspect ( ) ) ;
94
+ return done ( err ) ;
95
+ } ) ;
96
+ } ) ;
97
+ } ) ;
98
+
99
+ describe ( 'hmget' , function ( ) {
100
+ describe ( 'first argument is a string' , function ( ) {
101
+ it ( 'handles array of strings with undefined values in transaction (repro #344)' , function ( done ) {
102
+ client . multi ( ) . hmget ( "hash key 2" , "key 3" , "key 4" ) . exec ( function ( err , reply ) {
103
+ assert . strictEqual ( true , Array . isArray ( reply ) ) ;
104
+ assert . strictEqual ( 1 , reply . length ) ;
105
+ assert . strictEqual ( 2 , reply [ 0 ] . length ) ;
106
+ assert . equal ( null , reply [ 0 ] [ 0 ] ) ;
107
+ assert . equal ( null , reply [ 0 ] [ 1 ] ) ;
108
+ return done ( err ) ;
109
+ } ) ;
110
+ } ) ;
111
+ } ) ;
112
+
113
+ describe ( 'first argument is a buffer' , function ( ) {
114
+ it ( 'returns buffers for keys requested' , function ( done ) {
115
+ client . hmget ( new Buffer ( "hash key 2" ) , "key 1" , "key 2" , function ( err , reply ) {
116
+ assert . strictEqual ( true , Array . isArray ( reply ) ) ;
117
+ assert . strictEqual ( 2 , reply . length ) ;
118
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 0 ] ) ) ;
119
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 1 ] ) ) ;
120
+ assert . strictEqual ( "<Buffer 76 61 6c 20 31>" , reply [ 0 ] . inspect ( ) ) ;
121
+ assert . strictEqual ( "<Buffer 76 61 6c 20 32>" , reply [ 1 ] . inspect ( ) ) ;
122
+ return done ( err ) ;
123
+ } ) ;
124
+ } ) ;
125
+
126
+ it ( "returns buffers for keys requested in transaction" , function ( done ) {
127
+ client . multi ( ) . hmget ( new Buffer ( "hash key 2" ) , "key 1" , "key 2" ) . exec ( function ( err , reply ) {
128
+ assert . strictEqual ( true , Array . isArray ( reply ) ) ;
129
+ assert . strictEqual ( 1 , reply . length ) ;
130
+ assert . strictEqual ( 2 , reply [ 0 ] . length ) ;
131
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 0 ] [ 0 ] ) ) ;
132
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 0 ] [ 1 ] ) ) ;
133
+ assert . strictEqual ( "<Buffer 76 61 6c 20 31>" , reply [ 0 ] [ 0 ] . inspect ( ) ) ;
134
+ assert . strictEqual ( "<Buffer 76 61 6c 20 32>" , reply [ 0 ] [ 1 ] . inspect ( ) ) ;
135
+ return done ( err ) ;
136
+ } ) ;
137
+ } ) ;
138
+
139
+ it ( "returns buffers for keys requested in .batch" , function ( done ) {
140
+ client . batch ( ) . hmget ( new Buffer ( "hash key 2" ) , "key 1" , "key 2" ) . exec ( function ( err , reply ) {
141
+ assert . strictEqual ( true , Array . isArray ( reply ) ) ;
142
+ assert . strictEqual ( 1 , reply . length ) ;
143
+ assert . strictEqual ( 2 , reply [ 0 ] . length ) ;
144
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 0 ] [ 0 ] ) ) ;
145
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 0 ] [ 1 ] ) ) ;
146
+ assert . strictEqual ( "<Buffer 76 61 6c 20 31>" , reply [ 0 ] [ 0 ] . inspect ( ) ) ;
147
+ assert . strictEqual ( "<Buffer 76 61 6c 20 32>" , reply [ 0 ] [ 1 ] . inspect ( ) ) ;
148
+ return done ( err ) ;
149
+ } ) ;
150
+ } ) ;
151
+ } ) ;
152
+ } ) ;
153
+
154
+ describe ( 'hgetall' , function ( done ) {
155
+ describe ( 'first argument is a string' , function ( ) {
156
+ it ( 'returns buffer values' , function ( done ) {
157
+ client . hgetall ( "hash key 2" , function ( err , reply ) {
158
+ assert . strictEqual ( "object" , typeof reply ) ;
159
+ assert . strictEqual ( 2 , Object . keys ( reply ) . length ) ;
160
+ assert . strictEqual ( "<Buffer 76 61 6c 20 31>" , reply [ "key 1" ] . inspect ( ) ) ;
161
+ assert . strictEqual ( "<Buffer 76 61 6c 20 32>" , reply [ "key 2" ] . inspect ( ) ) ;
162
+ return done ( err ) ;
163
+ } ) ;
164
+ } ) ;
165
+
166
+ it ( 'returns buffer values when executed in transaction' , function ( done ) {
167
+ client . multi ( ) . hgetall ( "hash key 2" ) . exec ( function ( err , reply ) {
168
+ assert . strictEqual ( 1 , reply . length ) ;
169
+ assert . strictEqual ( "object" , typeof reply [ 0 ] ) ;
170
+ assert . strictEqual ( 2 , Object . keys ( reply [ 0 ] ) . length ) ;
171
+ assert . strictEqual ( "<Buffer 76 61 6c 20 31>" , reply [ 0 ] [ "key 1" ] . inspect ( ) ) ;
172
+ assert . strictEqual ( "<Buffer 76 61 6c 20 32>" , reply [ 0 ] [ "key 2" ] . inspect ( ) ) ;
173
+ return done ( err ) ;
174
+ } ) ;
175
+ } ) ;
176
+
177
+ it ( 'returns buffer values when executed in .batch' , function ( done ) {
178
+ client . batch ( ) . hgetall ( "hash key 2" ) . exec ( function ( err , reply ) {
179
+ assert . strictEqual ( 1 , reply . length ) ;
180
+ assert . strictEqual ( "object" , typeof reply [ 0 ] ) ;
181
+ assert . strictEqual ( 2 , Object . keys ( reply [ 0 ] ) . length ) ;
182
+ assert . strictEqual ( "<Buffer 76 61 6c 20 31>" , reply [ 0 ] [ "key 1" ] . inspect ( ) ) ;
183
+ assert . strictEqual ( "<Buffer 76 61 6c 20 32>" , reply [ 0 ] [ "key 2" ] . inspect ( ) ) ;
184
+ return done ( err ) ;
185
+ } ) ;
186
+ } ) ;
187
+ } ) ;
188
+
189
+ describe ( 'first argument is a buffer' , function ( ) {
190
+ it ( 'returns buffer values' , function ( done ) {
191
+ client . hgetall ( new Buffer ( "hash key 2" ) , function ( err , reply ) {
192
+ assert . strictEqual ( null , err ) ;
193
+ assert . strictEqual ( "object" , typeof reply ) ;
194
+ assert . strictEqual ( 2 , Object . keys ( reply ) . length ) ;
195
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ "key 1" ] ) ) ;
196
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ "key 2" ] ) ) ;
197
+ assert . strictEqual ( "<Buffer 76 61 6c 20 31>" , reply [ "key 1" ] . inspect ( ) ) ;
198
+ assert . strictEqual ( "<Buffer 76 61 6c 20 32>" , reply [ "key 2" ] . inspect ( ) ) ;
199
+ return done ( err ) ;
200
+ } ) ;
201
+ } ) ;
202
+
203
+ it ( 'returns buffer values when executed in transaction' , function ( done ) {
204
+ client . multi ( ) . hgetall ( new Buffer ( "hash key 2" ) ) . exec ( function ( err , reply ) {
205
+ assert . strictEqual ( 1 , reply . length ) ;
206
+ assert . strictEqual ( "object" , typeof reply [ 0 ] ) ;
207
+ assert . strictEqual ( 2 , Object . keys ( reply [ 0 ] ) . length ) ;
208
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 0 ] [ "key 1" ] ) ) ;
209
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 0 ] [ "key 2" ] ) ) ;
210
+ assert . strictEqual ( "<Buffer 76 61 6c 20 31>" , reply [ 0 ] [ "key 1" ] . inspect ( ) ) ;
211
+ assert . strictEqual ( "<Buffer 76 61 6c 20 32>" , reply [ 0 ] [ "key 2" ] . inspect ( ) ) ;
212
+ return done ( err ) ;
213
+ } ) ;
214
+ } ) ;
215
+
216
+ it ( 'returns buffer values when executed in .batch' , function ( done ) {
217
+ client . batch ( ) . hgetall ( new Buffer ( "hash key 2" ) ) . exec ( function ( err , reply ) {
218
+ assert . strictEqual ( 1 , reply . length ) ;
219
+ assert . strictEqual ( "object" , typeof reply [ 0 ] ) ;
220
+ assert . strictEqual ( 2 , Object . keys ( reply [ 0 ] ) . length ) ;
221
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 0 ] [ "key 1" ] ) ) ;
222
+ assert . strictEqual ( true , Buffer . isBuffer ( reply [ 0 ] [ "key 2" ] ) ) ;
223
+ assert . strictEqual ( "<Buffer 76 61 6c 20 31>" , reply [ 0 ] [ "key 1" ] . inspect ( ) ) ;
224
+ assert . strictEqual ( "<Buffer 76 61 6c 20 32>" , reply [ 0 ] [ "key 2" ] . inspect ( ) ) ;
225
+ return done ( err ) ;
226
+ } ) ;
227
+ } ) ;
228
+ } ) ;
229
+ } ) ;
230
+ } ) ;
231
+ } ) ;
232
+ } ) ;
0 commit comments