mirror of https://github.com/go-redis/redis.git
feat: Add redis v7's NX, XX, GT, LT expire variants
This commit is contained in:
parent
5aefa73462
commit
e19bbb26e2
32
commands.go
32
commands.go
|
@ -525,7 +525,37 @@ func (c cmdable) Exists(ctx context.Context, keys ...string) *IntCmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c cmdable) Expire(ctx context.Context, key string, expiration time.Duration) *BoolCmd {
|
func (c cmdable) Expire(ctx context.Context, key string, expiration time.Duration) *BoolCmd {
|
||||||
cmd := NewBoolCmd(ctx, "expire", key, formatSec(ctx, expiration))
|
return c.expire(ctx, key, expiration, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c cmdable) ExpireNX(ctx context.Context, key string, expiration time.Duration) *BoolCmd {
|
||||||
|
return c.expire(ctx, key, expiration, "NX")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c cmdable) ExpireXX(ctx context.Context, key string, expiration time.Duration) *BoolCmd {
|
||||||
|
return c.expire(ctx, key, expiration, "XX")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c cmdable) ExpireGT(ctx context.Context, key string, expiration time.Duration) *BoolCmd {
|
||||||
|
return c.expire(ctx, key, expiration, "GT")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c cmdable) ExpireLT(ctx context.Context, key string, expiration time.Duration) *BoolCmd {
|
||||||
|
return c.expire(ctx, key, expiration, "LT")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c cmdable) expire(
|
||||||
|
ctx context.Context, key string, expiration time.Duration, mode string,
|
||||||
|
) *BoolCmd {
|
||||||
|
args := make([]interface{}, 3, 4)
|
||||||
|
args[0] = "expire"
|
||||||
|
args[1] = key
|
||||||
|
args[2] = formatSec(ctx, expiration)
|
||||||
|
if mode != "" {
|
||||||
|
args = append(args, mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := NewBoolCmd(ctx, args...)
|
||||||
_ = c(ctx, cmd)
|
_ = c(ctx, cmd)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue