@@ -117,6 +117,8 @@ type Cmdable interface {
117
117
Get (ctx context.Context , key string ) * StringCmd
118
118
GetRange (ctx context.Context , key string , start , end int64 ) * StringCmd
119
119
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
120
122
Incr (ctx context.Context , key string ) * IntCmd
121
123
IncrBy (ctx context.Context , key string , value int64 ) * IntCmd
122
124
IncrByFloat (ctx context.Context , key string , value float64 ) * FloatCmd
@@ -160,6 +162,7 @@ type Cmdable interface {
160
162
HMSet (ctx context.Context , key string , values ... interface {}) * BoolCmd
161
163
HSetNX (ctx context.Context , key , field string , value interface {}) * BoolCmd
162
164
HVals (ctx context.Context , key string ) * StringSliceCmd
165
+ HRandField (ctx context.Context , key string , count int , withValues bool ) * StringSliceCmd
163
166
164
167
BLPop (ctx context.Context , timeout time.Duration , keys ... string ) * StringSliceCmd
165
168
BRPop (ctx context.Context , timeout time.Duration , keys ... string ) * StringSliceCmd
@@ -263,6 +266,7 @@ type Cmdable interface {
263
266
ZRevRank (ctx context.Context , key , member string ) * IntCmd
264
267
ZScore (ctx context.Context , key , member string ) * FloatCmd
265
268
ZUnionStore (ctx context.Context , dest string , store * ZStore ) * IntCmd
269
+ ZRandMember (ctx context.Context , key string , count int , withScores bool ) * StringSliceCmd
266
270
267
271
PFAdd (ctx context.Context , key string , els ... interface {}) * IntCmd
268
272
PFCount (ctx context.Context , keys ... string ) * IntCmd
@@ -710,6 +714,33 @@ func (c cmdable) GetSet(ctx context.Context, key string, value interface{}) *Str
710
714
return cmd
711
715
}
712
716
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
+
713
744
func (c cmdable ) Incr (ctx context.Context , key string ) * IntCmd {
714
745
cmd := NewIntCmd (ctx , "incr" , key )
715
746
_ = c (ctx , cmd )
@@ -1182,6 +1213,21 @@ func (c cmdable) HVals(ctx context.Context, key string) *StringSliceCmd {
1182
1213
return cmd
1183
1214
}
1184
1215
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
+
1185
1231
//------------------------------------------------------------------------------
1186
1232
1187
1233
func (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
2256
2302
return cmd
2257
2303
}
2258
2304
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
+
2259
2320
//------------------------------------------------------------------------------
2260
2321
2261
2322
func (c cmdable ) PFAdd (ctx context.Context , key string , els ... interface {}) * IntCmd {
0 commit comments