@@ -2814,7 +2814,7 @@ var _ = Describe("Commands", func() {
28142814
28152815 It ("should HGETDEL" , Label ("hash" , "HGETDEL" ), func () {
28162816 SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2817- // Setup: create a hash with three fields.
2817+
28182818 err := client .HSet (ctx , "myhash" , "f1" , "val1" , "f2" , "val2" , "f3" , "val3" ).Err ()
28192819 Expect (err ).NotTo (HaveOccurred ())
28202820
@@ -2837,8 +2837,6 @@ var _ = Describe("Commands", func() {
28372837 // HGETDEL on a key that does not exist.
28382838 res , err := client .HGetDel (ctx , "nonexistent" , "f1" , "f2" ).Result ()
28392839 Expect (err ).To (BeNil ())
2840- // Depending on your implementation, missing fields may return nil or empty strings.
2841- // Adjust the expectation accordingly.
28422840 Expect (res ).To (Equal ([]string {"" , "" }))
28432841 })
28442842
@@ -2847,38 +2845,46 @@ var _ = Describe("Commands", func() {
28472845 // -----------------------------
28482846 It ("should HGETEX with EX option" , Label ("hash" , "HGETEX" ), func () {
28492847 SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2850- // Setup: create a hash.
2848+
28512849 err := client .HSet (ctx , "myhash" , "f1" , "val1" , "f2" , "val2" ).Err ()
28522850 Expect (err ).NotTo (HaveOccurred ())
28532851
28542852 // 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 ()
28562858 Expect (err ).NotTo (HaveOccurred ())
28572859 Expect (res ).To (Equal ([]string {"val1" , "val2" }))
2858- // Optionally, verify TTL if your implementation exposes it.
28592860 })
28602861
28612862 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+
28642865 err := client .HSet (ctx , "myhash" , "f1" , "val1" , "f2" , "val2" ).Err ()
28652866 Expect (err ).NotTo (HaveOccurred ())
28662867
28672868 // 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 ()
28692871 Expect (err ).NotTo (HaveOccurred ())
28702872 Expect (res ).To (Equal ([]string {"val1" , "val2" }))
28712873 })
28722874
28732875 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+
28762878 err := client .HSet (ctx , "myhash" , "f1" , "val1" , "f2" , "val2" ).Err ()
28772879 Expect (err ).NotTo (HaveOccurred ())
28782880
28792881 // Set expiration at a specific Unix timestamp (60 seconds from now).
28802882 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 ()
28822888 Expect (err ).NotTo (HaveOccurred ())
28832889 Expect (res ).To (Equal ([]string {"val1" , "val2" }))
28842890 })
@@ -2887,75 +2893,62 @@ var _ = Describe("Commands", func() {
28872893 // HSETEX with FNX/FXX options
28882894 // -----------------------------
28892895 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" )
28932897
2894- // FNX: set field only if it does not exist.
2895- opt := redis.HSetXOptions {
2898+ opt := redis.HSetEXOptions {
28962899 Condition : redis .HSetEXFNX ,
28972900 ExpirationType : redis .HSetEXExpirationEX ,
28982901 ExpirationVal : 60 ,
28992902 }
29002903 res , err := client .HSetEXWithArgs (ctx , "myhash" , & opt , "f1" , "val1" ).Result ()
29012904 Expect (err ).NotTo (HaveOccurred ())
2902- // Expect the field to be set.
29032905 Expect (res ).To (Equal (int64 (1 )))
29042906
2905- opt = redis.HSetXOptions {
2907+ opt = redis.HSetEXOptions {
29062908 Condition : redis .HSetEXFNX ,
29072909 ExpirationType : redis .HSetEXExpirationEX ,
29082910 ExpirationVal : 60 ,
29092911 }
2910- // Attempt to set the same field again with FNX.
29112912 res , err = client .HSetEXWithArgs (ctx , "myhash" , & opt , "f1" , "val2" ).Result ()
29122913 Expect (err ).NotTo (HaveOccurred ())
2913- // Since the field already exists, no update occurs.
29142914 Expect (res ).To (Equal (int64 (0 )))
29152915 })
29162916
29172917 It ("should HSETEX with FXX condition" , Label ("hash" , "HSETEX" ), func () {
29182918 SkipBeforeRedisVersion (7.9 , "requires Redis 8.x" )
2919- // Setup: ensure field f2 exists.
2920- client .Del (ctx , "myhash" )
2919+
29212920 err := client .HSet (ctx , "myhash" , "f2" , "val1" ).Err ()
29222921 Expect (err ).NotTo (HaveOccurred ())
29232922
2924- opt := redis.HSetXOptions {
2923+ opt := redis.HSetEXOptions {
29252924 Condition : redis .HSetEXFXX ,
29262925 ExpirationType : redis .HSetEXExpirationEX ,
29272926 ExpirationVal : 60 ,
29282927 }
2929- // FXX: update field only if it exists.
29302928 res , err := client .HSetEXWithArgs (ctx , "myhash" , & opt , "f2" , "val2" ).Result ()
29312929 Expect (err ).NotTo (HaveOccurred ())
29322930 Expect (res ).To (Equal (int64 (1 )))
2933- opt = redis.HSetXOptions {
2931+ opt = redis.HSetEXOptions {
29342932 Condition : redis .HSetEXFXX ,
29352933 ExpirationType : redis .HSetEXExpirationEX ,
29362934 ExpirationVal : 60 ,
29372935 }
2938- // FXX on a non-existing field (f3) should not set the field.
29392936 res , err = client .HSetEXWithArgs (ctx , "myhash" , & opt , "f3" , "val3" ).Result ()
29402937 Expect (err ).NotTo (HaveOccurred ())
29412938 Expect (res ).To (Equal (int64 (0 )))
29422939 })
29432940
29442941 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 {
29492945 ExpirationType : redis .HSetEXExpirationEX ,
29502946 ExpirationVal : 60 ,
29512947 }
2952- // Set multiple fields at once (no condition).
29532948 res , err := client .HSetEXWithArgs (ctx , "myhash" , & opt , "f1" , "val1" , "f2" , "val2" ).Result ()
29542949 Expect (err ).NotTo (HaveOccurred ())
2955- // Assume 1 indicates all fields were set.
29562950 Expect (res ).To (Equal (int64 (1 )))
29572951
2958- // Verify that both fields are set.
29592952 values , err := client .HMGet (ctx , "myhash" , "f1" , "f2" ).Result ()
29602953 Expect (err ).NotTo (HaveOccurred ())
29612954 Expect (values ).To (Equal ([]interface {}{"val1" , "val2" }))
0 commit comments