@@ -2659,7 +2659,6 @@ var _ = Describe("Commands", func() {
2659
2659
Expect (res ).To (Equal ([]int64 {1 , 1 , - 2 }))
2660
2660
})
2661
2661
2662
-
2663
2662
It ("should HPExpire" , Label ("hash-expiration" , "NonRedisEnterprise" ), func () {
2664
2663
SkipBeforeRedisVersion (7.4 , "doesn't work with older redis stack images" )
2665
2664
res , err := client .HPExpire (ctx , "no_such_key" , 10 * time .Second , "field1" , "field2" , "field3" ).Result ()
@@ -2812,6 +2811,148 @@ var _ = Describe("Commands", func() {
2812
2811
Expect (err ).NotTo (HaveOccurred ())
2813
2812
Expect (res [0 ]).To (BeNumerically ("~" , 10 * time .Second .Milliseconds (), 1 ))
2814
2813
})
2814
+
2815
+ It ("should HGETDEL" , Label ("hash" , "HGETDEL" ), func () {
2816
+ SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2817
+
2818
+ err := client .HSet (ctx , "myhash" , "f1" , "val1" , "f2" , "val2" , "f3" , "val3" ).Err ()
2819
+ Expect (err ).NotTo (HaveOccurred ())
2820
+
2821
+ // Execute HGETDEL on fields f1 and f2.
2822
+ res , err := client .HGetDel (ctx , "myhash" , "f1" , "f2" ).Result ()
2823
+ Expect (err ).NotTo (HaveOccurred ())
2824
+ // Expect the returned values for f1 and f2.
2825
+ Expect (res ).To (Equal ([]string {"val1" , "val2" }))
2826
+
2827
+ // Verify that f1 and f2 have been deleted, while f3 remains.
2828
+ remaining , err := client .HMGet (ctx , "myhash" , "f1" , "f2" , "f3" ).Result ()
2829
+ Expect (err ).NotTo (HaveOccurred ())
2830
+ Expect (remaining [0 ]).To (BeNil ())
2831
+ Expect (remaining [1 ]).To (BeNil ())
2832
+ Expect (remaining [2 ]).To (Equal ("val3" ))
2833
+ })
2834
+
2835
+ It ("should return nil responses for HGETDEL on non-existent key" , Label ("hash" , "HGETDEL" ), func () {
2836
+ SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2837
+ // HGETDEL on a key that does not exist.
2838
+ res , err := client .HGetDel (ctx , "nonexistent" , "f1" , "f2" ).Result ()
2839
+ Expect (err ).To (BeNil ())
2840
+ Expect (res ).To (Equal ([]string {"" , "" }))
2841
+ })
2842
+
2843
+ // -----------------------------
2844
+ // HGETEX with various TTL options
2845
+ // -----------------------------
2846
+ It ("should HGETEX with EX option" , Label ("hash" , "HGETEX" ), func () {
2847
+ SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2848
+
2849
+ err := client .HSet (ctx , "myhash" , "f1" , "val1" , "f2" , "val2" ).Err ()
2850
+ Expect (err ).NotTo (HaveOccurred ())
2851
+
2852
+ // Call HGETEX with EX option and 60 seconds TTL.
2853
+ opt := redis.HGetEXOptions {
2854
+ ExpirationType : redis .HGetEXExpirationEX ,
2855
+ ExpirationVal : 60 ,
2856
+ }
2857
+ res , err := client .HGetEXWithArgs (ctx , "myhash" , & opt , "f1" , "f2" ).Result ()
2858
+ Expect (err ).NotTo (HaveOccurred ())
2859
+ Expect (res ).To (Equal ([]string {"val1" , "val2" }))
2860
+ })
2861
+
2862
+ It ("should HGETEX with PERSIST option" , Label ("hash" , "HGETEX" ), func () {
2863
+ SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2864
+
2865
+ err := client .HSet (ctx , "myhash" , "f1" , "val1" , "f2" , "val2" ).Err ()
2866
+ Expect (err ).NotTo (HaveOccurred ())
2867
+
2868
+ // Call HGETEX with PERSIST (no TTL value needed).
2869
+ opt := redis.HGetEXOptions {ExpirationType : redis .HGetEXExpirationPERSIST }
2870
+ res , err := client .HGetEXWithArgs (ctx , "myhash" , & opt , "f1" , "f2" ).Result ()
2871
+ Expect (err ).NotTo (HaveOccurred ())
2872
+ Expect (res ).To (Equal ([]string {"val1" , "val2" }))
2873
+ })
2874
+
2875
+ It ("should HGETEX with EXAT option" , Label ("hash" , "HGETEX" ), func () {
2876
+ SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2877
+
2878
+ err := client .HSet (ctx , "myhash" , "f1" , "val1" , "f2" , "val2" ).Err ()
2879
+ Expect (err ).NotTo (HaveOccurred ())
2880
+
2881
+ // Set expiration at a specific Unix timestamp (60 seconds from now).
2882
+ expireAt := time .Now ().Add (60 * time .Second ).Unix ()
2883
+ opt := redis.HGetEXOptions {
2884
+ ExpirationType : redis .HGetEXExpirationEXAT ,
2885
+ ExpirationVal : expireAt ,
2886
+ }
2887
+ res , err := client .HGetEXWithArgs (ctx , "myhash" , & opt , "f1" , "f2" ).Result ()
2888
+ Expect (err ).NotTo (HaveOccurred ())
2889
+ Expect (res ).To (Equal ([]string {"val1" , "val2" }))
2890
+ })
2891
+
2892
+ // -----------------------------
2893
+ // HSETEX with FNX/FXX options
2894
+ // -----------------------------
2895
+ It ("should HSETEX with FNX condition" , Label ("hash" , "HSETEX" ), func () {
2896
+ SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2897
+
2898
+ opt := redis.HSetEXOptions {
2899
+ Condition : redis .HSetEXFNX ,
2900
+ ExpirationType : redis .HSetEXExpirationEX ,
2901
+ ExpirationVal : 60 ,
2902
+ }
2903
+ res , err := client .HSetEXWithArgs (ctx , "myhash" , & opt , "f1" , "val1" ).Result ()
2904
+ Expect (err ).NotTo (HaveOccurred ())
2905
+ Expect (res ).To (Equal (int64 (1 )))
2906
+
2907
+ opt = redis.HSetEXOptions {
2908
+ Condition : redis .HSetEXFNX ,
2909
+ ExpirationType : redis .HSetEXExpirationEX ,
2910
+ ExpirationVal : 60 ,
2911
+ }
2912
+ res , err = client .HSetEXWithArgs (ctx , "myhash" , & opt , "f1" , "val2" ).Result ()
2913
+ Expect (err ).NotTo (HaveOccurred ())
2914
+ Expect (res ).To (Equal (int64 (0 )))
2915
+ })
2916
+
2917
+ It ("should HSETEX with FXX condition" , Label ("hash" , "HSETEX" ), func () {
2918
+ SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2919
+
2920
+ err := client .HSet (ctx , "myhash" , "f2" , "val1" ).Err ()
2921
+ Expect (err ).NotTo (HaveOccurred ())
2922
+
2923
+ opt := redis.HSetEXOptions {
2924
+ Condition : redis .HSetEXFXX ,
2925
+ ExpirationType : redis .HSetEXExpirationEX ,
2926
+ ExpirationVal : 60 ,
2927
+ }
2928
+ res , err := client .HSetEXWithArgs (ctx , "myhash" , & opt , "f2" , "val2" ).Result ()
2929
+ Expect (err ).NotTo (HaveOccurred ())
2930
+ Expect (res ).To (Equal (int64 (1 )))
2931
+ opt = redis.HSetEXOptions {
2932
+ Condition : redis .HSetEXFXX ,
2933
+ ExpirationType : redis .HSetEXExpirationEX ,
2934
+ ExpirationVal : 60 ,
2935
+ }
2936
+ res , err = client .HSetEXWithArgs (ctx , "myhash" , & opt , "f3" , "val3" ).Result ()
2937
+ Expect (err ).NotTo (HaveOccurred ())
2938
+ Expect (res ).To (Equal (int64 (0 )))
2939
+ })
2940
+
2941
+ It ("should HSETEX with multiple field operations" , Label ("hash" , "HSETEX" ), func () {
2942
+ SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2943
+
2944
+ opt := redis.HSetEXOptions {
2945
+ ExpirationType : redis .HSetEXExpirationEX ,
2946
+ ExpirationVal : 60 ,
2947
+ }
2948
+ res , err := client .HSetEXWithArgs (ctx , "myhash" , & opt , "f1" , "val1" , "f2" , "val2" ).Result ()
2949
+ Expect (err ).NotTo (HaveOccurred ())
2950
+ Expect (res ).To (Equal (int64 (1 )))
2951
+
2952
+ values , err := client .HMGet (ctx , "myhash" , "f1" , "f2" ).Result ()
2953
+ Expect (err ).NotTo (HaveOccurred ())
2954
+ Expect (values ).To (Equal ([]interface {}{"val1" , "val2" }))
2955
+ })
2815
2956
})
2816
2957
2817
2958
Describe ("hyperloglog" , func () {
0 commit comments