@@ -117,6 +117,8 @@ type Cmdable interface {
117117 Get (ctx context.Context , key string ) * StringCmd
118118 GetRange (ctx context.Context , key string , start , end int64 ) * StringCmd
119119 GetSet (ctx context.Context , key string , value interface {}) * StringCmd
120+ GetEX (ctx context.Context , key string , expiration time.Duration ) * StringCmd
121+ GetDel (ctx context.Context , key string ) * StringCmd
120122 Incr (ctx context.Context , key string ) * IntCmd
121123 IncrBy (ctx context.Context , key string , value int64 ) * IntCmd
122124 IncrByFloat (ctx context.Context , key string , value float64 ) * FloatCmd
@@ -160,6 +162,7 @@ type Cmdable interface {
160162 HMSet (ctx context.Context , key string , values ... interface {}) * BoolCmd
161163 HSetNX (ctx context.Context , key , field string , value interface {}) * BoolCmd
162164 HVals (ctx context.Context , key string ) * StringSliceCmd
165+ HRandField (ctx context.Context , key string , count int , withValues bool ) * StringSliceCmd
163166
164167 BLPop (ctx context.Context , timeout time.Duration , keys ... string ) * StringSliceCmd
165168 BRPop (ctx context.Context , timeout time.Duration , keys ... string ) * StringSliceCmd
@@ -263,6 +266,7 @@ type Cmdable interface {
263266 ZRevRank (ctx context.Context , key , member string ) * IntCmd
264267 ZScore (ctx context.Context , key , member string ) * FloatCmd
265268 ZUnionStore (ctx context.Context , dest string , store * ZStore ) * IntCmd
269+ ZRandMember (ctx context.Context , key string , count int , withScores bool ) * StringSliceCmd
266270
267271 PFAdd (ctx context.Context , key string , els ... interface {}) * IntCmd
268272 PFCount (ctx context.Context , keys ... string ) * IntCmd
@@ -710,6 +714,33 @@ func (c cmdable) GetSet(ctx context.Context, key string, value interface{}) *Str
710714 return cmd
711715}
712716
717+ // redis-server version >= 6.2.0.
718+ // A expiration of zero remove the time to live associated with the key(GetEX key persist).
719+ func (c cmdable ) GetEX (ctx context.Context , key string , expiration time.Duration ) * StringCmd {
720+ args := make ([]interface {}, 0 , 4 )
721+ args = append (args , "getex" , key )
722+ if expiration > 0 {
723+ if usePrecise (expiration ) {
724+ args = append (args , "px" , formatMs (ctx , expiration ))
725+ } else {
726+ args = append (args , "ex" , formatSec (ctx , expiration ))
727+ }
728+ } else if expiration == 0 {
729+ args = append (args , "persist" )
730+ }
731+
732+ cmd := NewStringCmd (ctx , args ... )
733+ _ = c (ctx , cmd )
734+ return cmd
735+ }
736+
737+ // redis-server version >= 6.2.0.
738+ func (c cmdable ) GetDel (ctx context.Context , key string ) * StringCmd {
739+ cmd := NewStringCmd (ctx , "getdel" , key )
740+ _ = c (ctx , cmd )
741+ return cmd
742+ }
743+
713744func (c cmdable ) Incr (ctx context.Context , key string ) * IntCmd {
714745 cmd := NewIntCmd (ctx , "incr" , key )
715746 _ = c (ctx , cmd )
@@ -1182,6 +1213,21 @@ func (c cmdable) HVals(ctx context.Context, key string) *StringSliceCmd {
11821213 return cmd
11831214}
11841215
1216+ // redis-server version >= 6.2.0.
1217+ func (c cmdable ) HRandField (ctx context.Context , key string , count int , withValues bool ) * StringSliceCmd {
1218+ args := make ([]interface {}, 0 , 4 )
1219+
1220+ // Although count=0 is meaningless, redis accepts count=0.
1221+ args = append (args , "hrandfield" , key , count )
1222+ if withValues {
1223+ args = append (args , "withvalues" )
1224+ }
1225+
1226+ cmd := NewStringSliceCmd (ctx , args ... )
1227+ _ = c (ctx , cmd )
1228+ return cmd
1229+ }
1230+
11851231//------------------------------------------------------------------------------
11861232
11871233func (c cmdable ) BLPop (ctx context.Context , timeout time.Duration , keys ... string ) * StringSliceCmd {
@@ -2256,6 +2302,21 @@ func (c cmdable) ZUnionStore(ctx context.Context, dest string, store *ZStore) *I
22562302 return cmd
22572303}
22582304
2305+ // redis-server version >= 6.2.0.
2306+ func (c cmdable ) ZRandMember (ctx context.Context , key string , count int , withScores bool ) * StringSliceCmd {
2307+ args := make ([]interface {}, 0 , 4 )
2308+
2309+ // Although count=0 is meaningless, redis accepts count=0.
2310+ args = append (args , "zrandmember" , key , count )
2311+ if withScores {
2312+ args = append (args , "withscores" )
2313+ }
2314+
2315+ cmd := NewStringSliceCmd (ctx , args ... )
2316+ _ = c (ctx , cmd )
2317+ return cmd
2318+ }
2319+
22592320//------------------------------------------------------------------------------
22602321
22612322func (c cmdable ) PFAdd (ctx context.Context , key string , els ... interface {}) * IntCmd {
0 commit comments