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
60
command.go
60
command.go
@ -4724,3 +4724,63 @@ func (cmd *ClusterShardsCmd) readReply(rd *proto.Reader) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
type RankScore struct {
|
||||
Rank int64
|
||||
Score float64
|
||||
}
|
||||
|
||||
type RankWithScoreCmd struct {
|
||||
baseCmd
|
||||
|
||||
val RankScore
|
||||
}
|
||||
|
||||
var _ Cmder = (*RankWithScoreCmd)(nil)
|
||||
|
||||
func NewRankWithScoreCmd(ctx context.Context, args ...interface{}) *RankWithScoreCmd {
|
||||
return &RankWithScoreCmd{
|
||||
baseCmd: baseCmd{
|
||||
ctx: ctx,
|
||||
args: args,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (cmd *RankWithScoreCmd) SetVal(val RankScore) {
|
||||
cmd.val = val
|
||||
}
|
||||
|
||||
func (cmd *RankWithScoreCmd) Val() RankScore {
|
||||
return cmd.val
|
||||
}
|
||||
|
||||
func (cmd *RankWithScoreCmd) Result() (RankScore, error) {
|
||||
return cmd.val, cmd.err
|
||||
}
|
||||
|
||||
func (cmd *RankWithScoreCmd) String() string {
|
||||
return cmdString(cmd, cmd.val)
|
||||
}
|
||||
|
||||
func (cmd *RankWithScoreCmd) readReply(rd *proto.Reader) error {
|
||||
if err := rd.ReadFixedArrayLen(2); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rank, err := rd.ReadInt()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
score, err := rd.ReadFloat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd.val = RankScore{Rank: rank, Score: score}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user