@@ -2814,7 +2814,7 @@ var _ = Describe("Commands", func() {
2814
2814
2815
2815
It ("should HGETDEL" , Label ("hash" , "HGETDEL" ), func () {
2816
2816
SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2817
- // Setup: create a hash with three fields.
2817
+
2818
2818
err := client .HSet (ctx , "myhash" , "f1" , "val1" , "f2" , "val2" , "f3" , "val3" ).Err ()
2819
2819
Expect (err ).NotTo (HaveOccurred ())
2820
2820
@@ -2837,8 +2837,6 @@ var _ = Describe("Commands", func() {
2837
2837
// HGETDEL on a key that does not exist.
2838
2838
res , err := client .HGetDel (ctx , "nonexistent" , "f1" , "f2" ).Result ()
2839
2839
Expect (err ).To (BeNil ())
2840
- // Depending on your implementation, missing fields may return nil or empty strings.
2841
- // Adjust the expectation accordingly.
2842
2840
Expect (res ).To (Equal ([]string {"" , "" }))
2843
2841
})
2844
2842
@@ -2847,38 +2845,46 @@ var _ = Describe("Commands", func() {
2847
2845
// -----------------------------
2848
2846
It ("should HGETEX with EX option" , Label ("hash" , "HGETEX" ), func () {
2849
2847
SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2850
- // Setup: create a hash.
2848
+
2851
2849
err := client .HSet (ctx , "myhash" , "f1" , "val1" , "f2" , "val2" ).Err ()
2852
2850
Expect (err ).NotTo (HaveOccurred ())
2853
2851
2854
2852
// Call HGETEX with EX option and 60 seconds TTL.
2855
- res , err := client .HGetEXWithArgs (ctx , "myhash" , redis .HGetEXExpirationEX , 60 , "f1" , "f2" ).Result ()
2853
+ opt := redis.HGetEXOptions {
2854
+ ExpirationType : redis .HGetEXExpirationEX ,
2855
+ ExpirationVal : 60 ,
2856
+ }
2857
+ res , err := client .HGetEXWithArgs (ctx , "myhash" , & opt , "f1" , "f2" ).Result ()
2856
2858
Expect (err ).NotTo (HaveOccurred ())
2857
2859
Expect (res ).To (Equal ([]string {"val1" , "val2" }))
2858
- // Optionally, verify TTL if your implementation exposes it.
2859
2860
})
2860
2861
2861
2862
It ("should HGETEX with PERSIST option" , Label ("hash" , "HGETEX" ), func () {
2862
- SkipBeforeRedisVersion (8 , "requires Redis 8.x" )
2863
- // Setup: create a hash.
2863
+ SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2864
+
2864
2865
err := client .HSet (ctx , "myhash" , "f1" , "val1" , "f2" , "val2" ).Err ()
2865
2866
Expect (err ).NotTo (HaveOccurred ())
2866
2867
2867
2868
// Call HGETEX with PERSIST (no TTL value needed).
2868
- res , err := client .HGetEXWithArgs (ctx , "myhash" , redis .HGetEXExpirationPERSIST , 0 , "f1" , "f2" ).Result ()
2869
+ opt := redis.HGetEXOptions {ExpirationType : redis .HGetEXExpirationPERSIST }
2870
+ res , err := client .HGetEXWithArgs (ctx , "myhash" , & opt , "f1" , "f2" ).Result ()
2869
2871
Expect (err ).NotTo (HaveOccurred ())
2870
2872
Expect (res ).To (Equal ([]string {"val1" , "val2" }))
2871
2873
})
2872
2874
2873
2875
It ("should HGETEX with EXAT option" , Label ("hash" , "HGETEX" ), func () {
2874
- SkipBeforeRedisVersion (8 , "requires Redis 8.x" )
2875
- // Setup: create a hash.
2876
+ SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2877
+
2876
2878
err := client .HSet (ctx , "myhash" , "f1" , "val1" , "f2" , "val2" ).Err ()
2877
2879
Expect (err ).NotTo (HaveOccurred ())
2878
2880
2879
2881
// Set expiration at a specific Unix timestamp (60 seconds from now).
2880
2882
expireAt := time .Now ().Add (60 * time .Second ).Unix ()
2881
- res , err := client .HGetEXWithArgs (ctx , "myhash" , redis .HGetEXExpirationEXAT , expireAt , "f1" , "f2" ).Result ()
2883
+ opt := redis.HGetEXOptions {
2884
+ ExpirationType : redis .HGetEXExpirationEXAT ,
2885
+ ExpirationVal : expireAt ,
2886
+ }
2887
+ res , err := client .HGetEXWithArgs (ctx , "myhash" , & opt , "f1" , "f2" ).Result ()
2882
2888
Expect (err ).NotTo (HaveOccurred ())
2883
2889
Expect (res ).To (Equal ([]string {"val1" , "val2" }))
2884
2890
})
@@ -2887,75 +2893,62 @@ var _ = Describe("Commands", func() {
2887
2893
// HSETEX with FNX/FXX options
2888
2894
// -----------------------------
2889
2895
It ("should HSETEX with FNX condition" , Label ("hash" , "HSETEX" ), func () {
2890
- SkipBeforeRedisVersion (8 , "requires Redis 8.x" )
2891
- // Ensure the key is removed.
2892
- client .Del (ctx , "myhash" )
2896
+ SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2893
2897
2894
- // FNX: set field only if it does not exist.
2895
- opt := redis.HSetXOptions {
2898
+ opt := redis.HSetEXOptions {
2896
2899
Condition : redis .HSetEXFNX ,
2897
2900
ExpirationType : redis .HSetEXExpirationEX ,
2898
2901
ExpirationVal : 60 ,
2899
2902
}
2900
2903
res , err := client .HSetEXWithArgs (ctx , "myhash" , & opt , "f1" , "val1" ).Result ()
2901
2904
Expect (err ).NotTo (HaveOccurred ())
2902
- // Expect the field to be set.
2903
2905
Expect (res ).To (Equal (int64 (1 )))
2904
2906
2905
- opt = redis.HSetXOptions {
2907
+ opt = redis.HSetEXOptions {
2906
2908
Condition : redis .HSetEXFNX ,
2907
2909
ExpirationType : redis .HSetEXExpirationEX ,
2908
2910
ExpirationVal : 60 ,
2909
2911
}
2910
- // Attempt to set the same field again with FNX.
2911
2912
res , err = client .HSetEXWithArgs (ctx , "myhash" , & opt , "f1" , "val2" ).Result ()
2912
2913
Expect (err ).NotTo (HaveOccurred ())
2913
- // Since the field already exists, no update occurs.
2914
2914
Expect (res ).To (Equal (int64 (0 )))
2915
2915
})
2916
2916
2917
2917
It ("should HSETEX with FXX condition" , Label ("hash" , "HSETEX" ), func () {
2918
2918
SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2919
- // Setup: ensure field f2 exists.
2920
- client .Del (ctx , "myhash" )
2919
+
2921
2920
err := client .HSet (ctx , "myhash" , "f2" , "val1" ).Err ()
2922
2921
Expect (err ).NotTo (HaveOccurred ())
2923
2922
2924
- opt := redis.HSetXOptions {
2923
+ opt := redis.HSetEXOptions {
2925
2924
Condition : redis .HSetEXFXX ,
2926
2925
ExpirationType : redis .HSetEXExpirationEX ,
2927
2926
ExpirationVal : 60 ,
2928
2927
}
2929
- // FXX: update field only if it exists.
2930
2928
res , err := client .HSetEXWithArgs (ctx , "myhash" , & opt , "f2" , "val2" ).Result ()
2931
2929
Expect (err ).NotTo (HaveOccurred ())
2932
2930
Expect (res ).To (Equal (int64 (1 )))
2933
- opt = redis.HSetXOptions {
2931
+ opt = redis.HSetEXOptions {
2934
2932
Condition : redis .HSetEXFXX ,
2935
2933
ExpirationType : redis .HSetEXExpirationEX ,
2936
2934
ExpirationVal : 60 ,
2937
2935
}
2938
- // FXX on a non-existing field (f3) should not set the field.
2939
2936
res , err = client .HSetEXWithArgs (ctx , "myhash" , & opt , "f3" , "val3" ).Result ()
2940
2937
Expect (err ).NotTo (HaveOccurred ())
2941
2938
Expect (res ).To (Equal (int64 (0 )))
2942
2939
})
2943
2940
2944
2941
It ("should HSETEX with multiple field operations" , Label ("hash" , "HSETEX" ), func () {
2945
- SkipBeforeRedisVersion (8 , "requires Redis 8.x" )
2946
- // Remove key if it exists.
2947
- client .Del (ctx , "myhash" )
2948
- opt := redis.HSetXOptions {
2942
+ SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2943
+
2944
+ opt := redis.HSetEXOptions {
2949
2945
ExpirationType : redis .HSetEXExpirationEX ,
2950
2946
ExpirationVal : 60 ,
2951
2947
}
2952
- // Set multiple fields at once (no condition).
2953
2948
res , err := client .HSetEXWithArgs (ctx , "myhash" , & opt , "f1" , "val1" , "f2" , "val2" ).Result ()
2954
2949
Expect (err ).NotTo (HaveOccurred ())
2955
- // Assume 1 indicates all fields were set.
2956
2950
Expect (res ).To (Equal (int64 (1 )))
2957
2951
2958
- // Verify that both fields are set.
2959
2952
values , err := client .HMGet (ctx , "myhash" , "f1" , "f2" ).Result ()
2960
2953
Expect (err ).NotTo (HaveOccurred ())
2961
2954
Expect (values ).To (Equal ([]interface {}{"val1" , "val2" }))
0 commit comments