mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
Add ZRANK, ZREVRANK WITHSCORE (#2531)
* feat: adding zrankwithscore and zrevrankwithscore commands : redis 7.2 * fix: test for non-existing members * fix: Error check * fix: string to float * add ZRankWithScore API for Cmdable interface Signed-off-by: monkey92t <golang@88.com> * add notes Signed-off-by: monkey92t <golang@88.com> --------- Signed-off-by: monkey92t <golang@88.com> Co-authored-by: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com> Co-authored-by: monkey92t <golang@88.com>
This commit is contained in:
committed by
GitHub
parent
38ca7c1680
commit
6ecbcf6c90
18
commands.go
18
commands.go
@ -373,6 +373,7 @@ type Cmdable interface {
|
||||
ZRangeArgsWithScores(ctx context.Context, z ZRangeArgs) *ZSliceCmd
|
||||
ZRangeStore(ctx context.Context, dst string, z ZRangeArgs) *IntCmd
|
||||
ZRank(ctx context.Context, key, member string) *IntCmd
|
||||
ZRankWithScore(ctx context.Context, key, member string) *RankWithScoreCmd
|
||||
ZRem(ctx context.Context, key string, members ...interface{}) *IntCmd
|
||||
ZRemRangeByRank(ctx context.Context, key string, start, stop int64) *IntCmd
|
||||
ZRemRangeByScore(ctx context.Context, key, min, max string) *IntCmd
|
||||
@ -383,6 +384,7 @@ type Cmdable interface {
|
||||
ZRevRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd
|
||||
ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd
|
||||
ZRevRank(ctx context.Context, key, member string) *IntCmd
|
||||
ZRevRankWithScore(ctx context.Context, key, member string) *RankWithScoreCmd
|
||||
ZScore(ctx context.Context, key, member string) *FloatCmd
|
||||
ZUnionStore(ctx context.Context, dest string, store *ZStore) *IntCmd
|
||||
ZRandMember(ctx context.Context, key string, count int) *StringSliceCmd
|
||||
@ -2884,6 +2886,14 @@ func (c cmdable) ZRank(ctx context.Context, key, member string) *IntCmd {
|
||||
return cmd
|
||||
}
|
||||
|
||||
// ZRankWithScore according to the Redis documentation, if member does not exist
|
||||
// in the sorted set or key does not exist, it will return a redis.Nil error.
|
||||
func (c cmdable) ZRankWithScore(ctx context.Context, key, member string) *RankWithScoreCmd {
|
||||
cmd := NewRankWithScoreCmd(ctx, "zrank", key, member, "withscore")
|
||||
_ = c(ctx, cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c cmdable) ZRem(ctx context.Context, key string, members ...interface{}) *IntCmd {
|
||||
args := make([]interface{}, 2, 2+len(members))
|
||||
args[0] = "zrem"
|
||||
@ -2924,6 +2934,8 @@ func (c cmdable) ZRevRange(ctx context.Context, key string, start, stop int64) *
|
||||
return cmd
|
||||
}
|
||||
|
||||
// ZRevRangeWithScores according to the Redis documentation, if member does not exist
|
||||
// in the sorted set or key does not exist, it will return a redis.Nil error.
|
||||
func (c cmdable) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd {
|
||||
cmd := NewZSliceCmd(ctx, "zrevrange", key, start, stop, "withscores")
|
||||
_ = c(ctx, cmd)
|
||||
@ -2974,6 +2986,12 @@ func (c cmdable) ZRevRank(ctx context.Context, key, member string) *IntCmd {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c cmdable) ZRevRankWithScore(ctx context.Context, key, member string) *RankWithScoreCmd {
|
||||
cmd := NewRankWithScoreCmd(ctx, "zrevrank", key, member, "withscore")
|
||||
_ = c(ctx, cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c cmdable) ZScore(ctx context.Context, key, member string) *FloatCmd {
|
||||
cmd := NewFloatCmd(ctx, "zscore", key, member)
|
||||
_ = c(ctx, cmd)
|
||||
|
Reference in New Issue
Block a user