@@ -193,6 +193,40 @@ var _ = Describe("Commands", func() {
193
193
Expect (r .Val ()).To (Equal (int64 (0 )))
194
194
})
195
195
196
+ It ("should ClientKillByFilter with MAXAGE" , func () {
197
+ var s []string
198
+ started := make (chan bool )
199
+ done := make (chan bool )
200
+
201
+ go func () {
202
+ defer GinkgoRecover ()
203
+
204
+ started <- true
205
+ blpop := client .BLPop (ctx , 0 , "list" )
206
+ Expect (blpop .Val ()).To (Equal (s ))
207
+ done <- true
208
+ }()
209
+ <- started
210
+
211
+ select {
212
+ case <- done :
213
+ Fail ("BLPOP is not blocked." )
214
+ case <- time .After (2 * time .Second ):
215
+ // ok
216
+ }
217
+
218
+ killed := client .ClientKillByFilter (ctx , "MAXAGE" , "1" )
219
+ Expect (killed .Err ()).NotTo (HaveOccurred ())
220
+ Expect (killed .Val ()).To (Equal (int64 (2 )))
221
+
222
+ select {
223
+ case <- done :
224
+ // ok
225
+ case <- time .After (time .Second ):
226
+ Fail ("BLPOP is still blocked." )
227
+ }
228
+ })
229
+
196
230
It ("should ClientID" , func () {
197
231
err := client .ClientID (ctx ).Err ()
198
232
Expect (err ).NotTo (HaveOccurred ())
@@ -2448,6 +2482,154 @@ var _ = Describe("Commands", func() {
2448
2482
Equal ([]redis.KeyValue {{Key : "key2" , Value : "hello2" }}),
2449
2483
))
2450
2484
})
2485
+
2486
+ It ("should HExpire" , Label ("hash-expiration" , "NonRedisEnterprise" ), func () {
2487
+ res , err := client .HExpire (ctx , "no_such_key" , 10 , "field1" , "field2" , "field3" ).Result ()
2488
+ Expect (err ).To (BeNil ())
2489
+ for i := 0 ; i < 100 ; i ++ {
2490
+ sadd := client .HSet (ctx , "myhash" , fmt .Sprintf ("key%d" , i ), "hello" )
2491
+ Expect (sadd .Err ()).NotTo (HaveOccurred ())
2492
+ }
2493
+
2494
+ res , err = client .HExpire (ctx , "myhash" , 10 , "key1" , "key2" , "key200" ).Result ()
2495
+ Expect (err ).NotTo (HaveOccurred ())
2496
+ Expect (res ).To (Equal ([]int64 {1 , 1 , - 2 }))
2497
+ })
2498
+
2499
+ It ("should HPExpire" , Label ("hash-expiration" , "NonRedisEnterprise" ), func () {
2500
+ _ , err := client .HPExpire (ctx , "no_such_key" , 10 , "field1" , "field2" , "field3" ).Result ()
2501
+ Expect (err ).To (BeNil ())
2502
+ for i := 0 ; i < 100 ; i ++ {
2503
+ sadd := client .HSet (ctx , "myhash" , fmt .Sprintf ("key%d" , i ), "hello" )
2504
+ Expect (sadd .Err ()).NotTo (HaveOccurred ())
2505
+ }
2506
+
2507
+ res , err := client .HPExpire (ctx , "myhash" , 10 , "key1" , "key2" , "key200" ).Result ()
2508
+ Expect (err ).NotTo (HaveOccurred ())
2509
+ Expect (res ).To (Equal ([]int64 {1 , 1 , - 2 }))
2510
+ })
2511
+
2512
+ It ("should HExpireAt" , Label ("hash-expiration" , "NonRedisEnterprise" ), func () {
2513
+
2514
+ _ , err := client .HExpireAt (ctx , "no_such_key" , time .Now ().Add (10 * time .Second ), "field1" , "field2" , "field3" ).Result ()
2515
+ Expect (err ).To (BeNil ())
2516
+ for i := 0 ; i < 100 ; i ++ {
2517
+ sadd := client .HSet (ctx , "myhash" , fmt .Sprintf ("key%d" , i ), "hello" )
2518
+ Expect (sadd .Err ()).NotTo (HaveOccurred ())
2519
+ }
2520
+
2521
+ res , err := client .HExpireAt (ctx , "myhash" , time .Now ().Add (10 * time .Second ), "key1" , "key2" , "key200" ).Result ()
2522
+ Expect (err ).NotTo (HaveOccurred ())
2523
+ Expect (res ).To (Equal ([]int64 {1 , 1 , - 2 }))
2524
+ })
2525
+
2526
+ It ("should HPExpireAt" , Label ("hash-expiration" , "NonRedisEnterprise" ), func () {
2527
+
2528
+ _ , err := client .HPExpireAt (ctx , "no_such_key" , time .Now ().Add (10 * time .Second ), "field1" , "field2" , "field3" ).Result ()
2529
+ Expect (err ).To (BeNil ())
2530
+ for i := 0 ; i < 100 ; i ++ {
2531
+ sadd := client .HSet (ctx , "myhash" , fmt .Sprintf ("key%d" , i ), "hello" )
2532
+ Expect (sadd .Err ()).NotTo (HaveOccurred ())
2533
+ }
2534
+
2535
+ res , err := client .HPExpireAt (ctx , "myhash" , time .Now ().Add (10 * time .Second ), "key1" , "key2" , "key200" ).Result ()
2536
+ Expect (err ).NotTo (HaveOccurred ())
2537
+ Expect (res ).To (Equal ([]int64 {1 , 1 , - 2 }))
2538
+ })
2539
+
2540
+ It ("should HPersist" , Label ("hash-expiration" , "NonRedisEnterprise" ), func () {
2541
+
2542
+ _ , err := client .HPersist (ctx , "no_such_key" , "field1" , "field2" , "field3" ).Result ()
2543
+ Expect (err ).To (BeNil ())
2544
+ for i := 0 ; i < 100 ; i ++ {
2545
+ sadd := client .HSet (ctx , "myhash" , fmt .Sprintf ("key%d" , i ), "hello" )
2546
+ Expect (sadd .Err ()).NotTo (HaveOccurred ())
2547
+ }
2548
+
2549
+ res , err := client .HPersist (ctx , "myhash" , "key1" , "key2" , "key200" ).Result ()
2550
+ Expect (err ).NotTo (HaveOccurred ())
2551
+ Expect (res ).To (Equal ([]int64 {- 1 , - 1 , - 2 }))
2552
+
2553
+ res , err = client .HExpire (ctx , "myhash" , 10 , "key1" , "key200" ).Result ()
2554
+ Expect (err ).NotTo (HaveOccurred ())
2555
+ Expect (res ).To (Equal ([]int64 {1 , - 2 }))
2556
+
2557
+ res , err = client .HPersist (ctx , "myhash" , "key1" , "key2" , "key200" ).Result ()
2558
+ Expect (err ).NotTo (HaveOccurred ())
2559
+ Expect (res ).To (Equal ([]int64 {1 , - 1 , - 2 }))
2560
+ })
2561
+
2562
+ It ("should HExpireTime" , Label ("hash-expiration" , "NonRedisEnterprise" ), func () {
2563
+
2564
+ _ , err := client .HExpireTime (ctx , "no_such_key" , "field1" , "field2" , "field3" ).Result ()
2565
+ Expect (err ).To (BeNil ())
2566
+ for i := 0 ; i < 100 ; i ++ {
2567
+ sadd := client .HSet (ctx , "myhash" , fmt .Sprintf ("key%d" , i ), "hello" )
2568
+ Expect (sadd .Err ()).NotTo (HaveOccurred ())
2569
+ }
2570
+
2571
+ res , err := client .HExpire (ctx , "myhash" , 10 , "key1" , "key200" ).Result ()
2572
+ Expect (err ).NotTo (HaveOccurred ())
2573
+ Expect (res ).To (Equal ([]int64 {1 , - 2 }))
2574
+
2575
+ res , err = client .HExpireTime (ctx , "myhash" , "key1" , "key2" , "key200" ).Result ()
2576
+ Expect (err ).NotTo (HaveOccurred ())
2577
+ Expect (res [0 ]).To (BeNumerically ("~" , time .Now ().Add (10 * time .Second ).Unix (), 1 ))
2578
+ })
2579
+
2580
+ It ("should HPExpireTime" , Label ("hash-expiration" , "NonRedisEnterprise" ), func () {
2581
+
2582
+ _ , err := client .HPExpireTime (ctx , "no_such_key" , "field1" , "field2" , "field3" ).Result ()
2583
+ Expect (err ).To (BeNil ())
2584
+ for i := 0 ; i < 100 ; i ++ {
2585
+ sadd := client .HSet (ctx , "myhash" , fmt .Sprintf ("key%d" , i ), "hello" )
2586
+ Expect (sadd .Err ()).NotTo (HaveOccurred ())
2587
+ }
2588
+
2589
+ res , err := client .HExpire (ctx , "myhash" , 10 , "key1" , "key200" ).Result ()
2590
+ Expect (err ).NotTo (HaveOccurred ())
2591
+ Expect (res ).To (Equal ([]int64 {1 , - 2 }))
2592
+
2593
+ res , err = client .HPExpireTime (ctx , "myhash" , "key1" , "key2" , "key200" ).Result ()
2594
+ Expect (err ).NotTo (HaveOccurred ())
2595
+ Expect (res ).To (BeEquivalentTo ([]int64 {time .Now ().Add (10 * time .Second ).UnixMilli (), - 1 , - 2 }))
2596
+ })
2597
+
2598
+ It ("should HTTL" , Label ("hash-expiration" , "NonRedisEnterprise" ), func () {
2599
+
2600
+ _ , err := client .HTTL (ctx , "no_such_key" , "field1" , "field2" , "field3" ).Result ()
2601
+ Expect (err ).To (BeNil ())
2602
+ for i := 0 ; i < 100 ; i ++ {
2603
+ sadd := client .HSet (ctx , "myhash" , fmt .Sprintf ("key%d" , i ), "hello" )
2604
+ Expect (sadd .Err ()).NotTo (HaveOccurred ())
2605
+ }
2606
+
2607
+ res , err := client .HExpire (ctx , "myhash" , 10 , "key1" , "key200" ).Result ()
2608
+ Expect (err ).NotTo (HaveOccurred ())
2609
+ Expect (res ).To (Equal ([]int64 {1 , - 2 }))
2610
+
2611
+ res , err = client .HTTL (ctx , "myhash" , "key1" , "key2" , "key200" ).Result ()
2612
+ Expect (err ).NotTo (HaveOccurred ())
2613
+ Expect (res ).To (Equal ([]int64 {10 , - 1 , - 2 }))
2614
+ })
2615
+
2616
+ It ("should HPTTL" , Label ("hash-expiration" , "NonRedisEnterprise" ), func () {
2617
+
2618
+ _ , err := client .HPTTL (ctx , "no_such_key" , "field1" , "field2" , "field3" ).Result ()
2619
+ Expect (err ).To (BeNil ())
2620
+ for i := 0 ; i < 100 ; i ++ {
2621
+ sadd := client .HSet (ctx , "myhash" , fmt .Sprintf ("key%d" , i ), "hello" )
2622
+ Expect (sadd .Err ()).NotTo (HaveOccurred ())
2623
+ }
2624
+
2625
+ res , err := client .HExpire (ctx , "myhash" , 10 , "key1" , "key200" ).Result ()
2626
+ Expect (err ).NotTo (HaveOccurred ())
2627
+ Expect (res ).To (Equal ([]int64 {1 , - 2 }))
2628
+
2629
+ res , err = client .HPTTL (ctx , "myhash" , "key1" , "key2" , "key200" ).Result ()
2630
+ Expect (err ).NotTo (HaveOccurred ())
2631
+ Expect (res [0 ]).To (BeNumerically ("~" , 10 * time .Second .Milliseconds (), 1 ))
2632
+ })
2451
2633
})
2452
2634
2453
2635
Describe ("hyperloglog" , func () {
0 commit comments