@@ -525,7 +525,37 @@ func (c cmdable) Exists(ctx context.Context, keys ...string) *IntCmd {
525
525
}
526
526
527
527
func (c cmdable ) Expire (ctx context.Context , key string , expiration time.Duration ) * BoolCmd {
528
- cmd := NewBoolCmd (ctx , "expire" , key , formatSec (ctx , expiration ))
528
+ return c .expire (ctx , key , expiration , "" )
529
+ }
530
+
531
+ func (c cmdable ) ExpireNX (ctx context.Context , key string , expiration time.Duration ) * BoolCmd {
532
+ return c .expire (ctx , key , expiration , "NX" )
533
+ }
534
+
535
+ func (c cmdable ) ExpireXX (ctx context.Context , key string , expiration time.Duration ) * BoolCmd {
536
+ return c .expire (ctx , key , expiration , "XX" )
537
+ }
538
+
539
+ func (c cmdable ) ExpireGT (ctx context.Context , key string , expiration time.Duration ) * BoolCmd {
540
+ return c .expire (ctx , key , expiration , "GT" )
541
+ }
542
+
543
+ func (c cmdable ) ExpireLT (ctx context.Context , key string , expiration time.Duration ) * BoolCmd {
544
+ return c .expire (ctx , key , expiration , "LT" )
545
+ }
546
+
547
+ func (c cmdable ) expire (
548
+ ctx context.Context , key string , expiration time.Duration , mode string ,
549
+ ) * BoolCmd {
550
+ args := make ([]interface {}, 3 , 4 )
551
+ args [0 ] = "expire"
552
+ args [1 ] = key
553
+ args [2 ] = formatSec (ctx , expiration )
554
+ if mode != "" {
555
+ args = append (args , mode )
556
+ }
557
+
558
+ cmd := NewBoolCmd (ctx , args ... )
529
559
_ = c (ctx , cmd )
530
560
return cmd
531
561
}
0 commit comments