@@ -1935,6 +1935,137 @@ var _ = Describe("Commands", func() {
19351935 Expect (mSetNX .Val ()).To (Equal (true ))
19361936 })
19371937
1938+ It ("should MSetEX" , func () {
1939+ SkipBeforeRedisVersion (8.3 , "MSetEX is available since redis 8.4" )
1940+ args := redis.MSetEXArgs {
1941+ Expiration : & redis.ExpirationOption {
1942+ Mode : redis .EX ,
1943+ Value : 1 ,
1944+ },
1945+ }
1946+ mSetEX := client .MSetEX (ctx , args , "key1" , "hello1" , "key2" , "hello2" )
1947+ Expect (mSetEX .Err ()).NotTo (HaveOccurred ())
1948+ Expect (mSetEX .Val ()).To (Equal (int64 (1 )))
1949+
1950+ // Verify keys were set
1951+ val1 := client .Get (ctx , "key1" )
1952+ Expect (val1 .Err ()).NotTo (HaveOccurred ())
1953+ Expect (val1 .Val ()).To (Equal ("hello1" ))
1954+
1955+ val2 := client .Get (ctx , "key2" )
1956+ Expect (val2 .Err ()).NotTo (HaveOccurred ())
1957+ Expect (val2 .Val ()).To (Equal ("hello2" ))
1958+
1959+ // Verify TTL was set
1960+ ttl1 := client .TTL (ctx , "key1" )
1961+ Expect (ttl1 .Err ()).NotTo (HaveOccurred ())
1962+ Expect (ttl1 .Val ()).To (BeNumerically (">" , 0 ))
1963+ Expect (ttl1 .Val ()).To (BeNumerically ("<=" , 1 * time .Second ))
1964+
1965+ ttl2 := client .TTL (ctx , "key2" )
1966+ Expect (ttl2 .Err ()).NotTo (HaveOccurred ())
1967+ Expect (ttl2 .Val ()).To (BeNumerically (">" , 0 ))
1968+ Expect (ttl2 .Val ()).To (BeNumerically ("<=" , 1 * time .Second ))
1969+ })
1970+
1971+ It ("should MSetEX with NX mode" , func () {
1972+ SkipBeforeRedisVersion (8.3 , "MSetEX is available since redis 8.4" )
1973+
1974+ client .Set (ctx , "key1" , "existing" , 0 )
1975+
1976+ // Try to set with NX mode - should fail because key1 exists
1977+ args := redis.MSetEXArgs {
1978+ Condition : redis .NX ,
1979+ Expiration : & redis.ExpirationOption {
1980+ Mode : redis .EX ,
1981+ Value : 1 ,
1982+ },
1983+ }
1984+ mSetEX := client .MSetEX (ctx , args , "key1" , "new1" , "key2" , "new2" )
1985+ Expect (mSetEX .Err ()).NotTo (HaveOccurred ())
1986+ Expect (mSetEX .Val ()).To (Equal (int64 (0 )))
1987+
1988+ val1 := client .Get (ctx , "key1" )
1989+ Expect (val1 .Err ()).NotTo (HaveOccurred ())
1990+ Expect (val1 .Val ()).To (Equal ("existing" ))
1991+
1992+ val2 := client .Get (ctx , "key2" )
1993+ Expect (val2 .Err ()).To (Equal (redis .Nil ))
1994+
1995+ client .Del (ctx , "key1" )
1996+
1997+ // Now try with NX mode when keys don't exist - should succeed
1998+ mSetEX = client .MSetEX (ctx , args , "key1" , "new1" , "key2" , "new2" )
1999+ Expect (mSetEX .Err ()).NotTo (HaveOccurred ())
2000+ Expect (mSetEX .Val ()).To (Equal (int64 (1 )))
2001+
2002+ val1 = client .Get (ctx , "key1" )
2003+ Expect (val1 .Err ()).NotTo (HaveOccurred ())
2004+ Expect (val1 .Val ()).To (Equal ("new1" ))
2005+
2006+ val2 = client .Get (ctx , "key2" )
2007+ Expect (val2 .Err ()).NotTo (HaveOccurred ())
2008+ Expect (val2 .Val ()).To (Equal ("new2" ))
2009+ })
2010+
2011+ It ("should MSetEX with XX mode" , func () {
2012+ SkipBeforeRedisVersion (8.3 , "MSetEX is available since redis 8.4" )
2013+
2014+ args := redis.MSetEXArgs {
2015+ Condition : redis .XX ,
2016+ Expiration : & redis.ExpirationOption {
2017+ Mode : redis .EX ,
2018+ Value : 1 ,
2019+ },
2020+ }
2021+ mSetEX := client .MSetEX (ctx , args , "key1" , "new1" , "key2" , "new2" )
2022+ Expect (mSetEX .Err ()).NotTo (HaveOccurred ())
2023+ Expect (mSetEX .Val ()).To (Equal (int64 (0 )))
2024+
2025+ client .Set (ctx , "key1" , "existing1" , 0 )
2026+ client .Set (ctx , "key2" , "existing2" , 0 )
2027+
2028+ mSetEX = client .MSetEX (ctx , args , "key1" , "new1" , "key2" , "new2" )
2029+ Expect (mSetEX .Err ()).NotTo (HaveOccurred ())
2030+ Expect (mSetEX .Val ()).To (Equal (int64 (1 )))
2031+
2032+ val1 := client .Get (ctx , "key1" )
2033+ Expect (val1 .Err ()).NotTo (HaveOccurred ())
2034+ Expect (val1 .Val ()).To (Equal ("new1" ))
2035+
2036+ val2 := client .Get (ctx , "key2" )
2037+ Expect (val2 .Err ()).NotTo (HaveOccurred ())
2038+ Expect (val2 .Val ()).To (Equal ("new2" ))
2039+
2040+ ttl1 := client .TTL (ctx , "key1" )
2041+ Expect (ttl1 .Err ()).NotTo (HaveOccurred ())
2042+ Expect (ttl1 .Val ()).To (BeNumerically (">" , 0 ))
2043+ })
2044+
2045+ It ("should MSetEX with map" , func () {
2046+ SkipBeforeRedisVersion (8.3 , "MSetEX is available since redis 8.4" )
2047+ args := redis.MSetEXArgs {
2048+ Expiration : & redis.ExpirationOption {
2049+ Mode : redis .EX ,
2050+ Value : 1 ,
2051+ },
2052+ }
2053+ mSetEX := client .MSetEX (ctx , args , map [string ]interface {}{
2054+ "key1" : "value1" ,
2055+ "key2" : "value2" ,
2056+ })
2057+ Expect (mSetEX .Err ()).NotTo (HaveOccurred ())
2058+ Expect (mSetEX .Val ()).To (Equal (int64 (1 )))
2059+
2060+ val1 := client .Get (ctx , "key1" )
2061+ Expect (val1 .Err ()).NotTo (HaveOccurred ())
2062+ Expect (val1 .Val ()).To (Equal ("value1" ))
2063+
2064+ val2 := client .Get (ctx , "key2" )
2065+ Expect (val2 .Err ()).NotTo (HaveOccurred ())
2066+ Expect (val2 .Val ()).To (Equal ("value2" ))
2067+ })
2068+
19382069 It ("should SetWithArgs with TTL" , func () {
19392070 args := redis.SetArgs {
19402071 TTL : 500 * time .Millisecond ,
0 commit comments