@@ -94,6 +94,12 @@ func testCommand(t *testing.T, testType string, rdb *redis.Client, sleepFn func(
94
94
ast .Equal (res , "" )
95
95
ast .Equal (err , redis .Nil )
96
96
97
+ _type , _ := rdb .Type (ctx , "foo" ).Result ()
98
+ ast .Equal (_type , "string" )
99
+
100
+ _type , _ = rdb .Type (ctx , "not-exist" ).Result ()
101
+ ast .Equal (_type , "none" )
102
+
97
103
n , _ := rdb .Del (ctx , "foo" , "none" ).Result ()
98
104
ast .Equal (n , int64 (1 ))
99
105
// setex
@@ -150,6 +156,9 @@ func testCommand(t *testing.T, testType string, rdb *redis.Client, sleepFn func(
150
156
res , _ = rdb .Incr (ctx , "testInt" ).Result ()
151
157
ast .Equal (res , int64 (2 ))
152
158
159
+ _type , _ := rdb .Type (ctx , "testInt" ).Result ()
160
+ ast .Equal (_type , "string" )
161
+
153
162
// get int
154
163
str , _ := rdb .Get (ctx , "testInt" ).Result ()
155
164
ast .Equal (str , "2" )
@@ -188,10 +197,16 @@ func testCommand(t *testing.T, testType string, rdb *redis.Client, sleepFn func(
188
197
ast .Nil (err )
189
198
}
190
199
200
+ _ , err = rdb .HGet (ctx , "map" , "not-exist" ).Result ()
201
+ ast .Equal (err , redis .Nil )
202
+
191
203
// hgetall
192
204
resm , _ := rdb .HGetAll (ctx , "map" ).Result ()
193
205
ast .Equal (len (resm ), 100 )
194
206
207
+ _type , _ := rdb .Type (ctx , "map" ).Result ()
208
+ ast .Equal (_type , "hash" )
209
+
195
210
// hdel
196
211
res , _ = rdb .HDel (ctx , "map" , keys [0 :10 ]... ).Result ()
197
212
ast .Equal (res , int64 (10 ))
@@ -228,6 +243,9 @@ func testCommand(t *testing.T, testType string, rdb *redis.Client, sleepFn func(
228
243
n , _ = rdb .RPush (ctx , "list" , "4" , "5" , "6" ).Result ()
229
244
ast .Equal (n , int64 (6 ))
230
245
246
+ _type , _ := rdb .Type (ctx , "list" ).Result ()
247
+ ast .Equal (_type , "list" )
248
+
231
249
// list: [1,2,3,4,5,6]
232
250
// lrange
233
251
res , _ := rdb .LRange (ctx , "list" , 0 , - 1 ).Result ()
@@ -261,6 +279,9 @@ func testCommand(t *testing.T, testType string, rdb *redis.Client, sleepFn func(
261
279
val , _ = rdb .RPop (ctx , "list" ).Result ()
262
280
ast .Equal (val , "6" )
263
281
282
+ n , _ = rdb .LPush (ctx , "list" , "6" ).Result ()
283
+ ast .Equal (n , int64 (5 ))
284
+
264
285
// pop nil
265
286
{
266
287
_ , err := rdb .LPop (ctx , "list-empty" ).Result ()
@@ -301,6 +322,9 @@ func testCommand(t *testing.T, testType string, rdb *redis.Client, sleepFn func(
301
322
mems , _ := rdb .SMembers (ctx , "set" ).Result ()
302
323
ast .ElementsMatch (mems , []string {"k1" , "k2" , "k3" })
303
324
325
+ _type , _ := rdb .Type (ctx , "set" ).Result ()
326
+ ast .Equal (_type , "set" )
327
+
304
328
// spop
305
329
for i := 0 ; i < 3 ; i ++ {
306
330
val , _ := rdb .SPop (ctx , "set" ).Result ()
@@ -324,6 +348,9 @@ func testCommand(t *testing.T, testType string, rdb *redis.Client, sleepFn func(
324
348
_ , err = rdb .SRem (ctx , "key" , "1" ).Result ()
325
349
ast .Equal (err .Error (), errWrongType .Error ())
326
350
351
+ _ , err = rdb .SMembers (ctx , "key" ).Result ()
352
+ ast .Equal (err .Error (), errWrongType .Error ())
353
+
327
354
_ , err = rdb .SPop (ctx , "key" ).Result ()
328
355
ast .Equal (err .Error (), errWrongType .Error ())
329
356
})
@@ -338,6 +365,9 @@ func testCommand(t *testing.T, testType string, rdb *redis.Client, sleepFn func(
338
365
redis.Z {Member : "user3" , Score : 100 }).Result ()
339
366
ast .Equal (n , int64 (2 ))
340
367
368
+ _type , _ := rdb .Type (ctx , "rank" ).Result ()
369
+ ast .Equal (_type , "zset" )
370
+
341
371
// zrank
342
372
{
343
373
res , _ := rdb .ZRank (ctx , "rank" , "user1" ).Result ()
@@ -411,6 +441,9 @@ func testCommand(t *testing.T, testType string, rdb *redis.Client, sleepFn func(
411
441
_ , err = rdb .ZRank (ctx , "key" , "member1" ).Result ()
412
442
ast .Equal (err .Error (), errWrongType .Error ())
413
443
444
+ _ , err = rdb .ZRange (ctx , "key" , 0 , - 1 ).Result ()
445
+ ast .Equal (err .Error (), errWrongType .Error ())
446
+
414
447
_ , err = rdb .ZRem (ctx , "key" , "member1" ).Result ()
415
448
ast .Equal (err .Error (), errWrongType .Error ())
416
449
0 commit comments