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
@ -4737,6 +4737,31 @@ var _ = Describe("Commands", func() {
|
||||
Expect(zRank.Val()).To(Equal(int64(0)))
|
||||
})
|
||||
|
||||
It("should ZRankWithScore", func() {
|
||||
err := client.ZAdd(ctx, "zset", redis.Z{Score: 1, Member: "one"}).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = client.ZAdd(ctx, "zset", redis.Z{Score: 2, Member: "two"}).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = client.ZAdd(ctx, "zset", redis.Z{Score: 3, Member: "three"}).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
zRankWithScore := client.ZRankWithScore(ctx, "zset", "one")
|
||||
Expect(zRankWithScore.Err()).NotTo(HaveOccurred())
|
||||
Expect(zRankWithScore.Result()).To(Equal(redis.RankScore{Rank: 0, Score: 1}))
|
||||
|
||||
zRankWithScore = client.ZRankWithScore(ctx, "zset", "two")
|
||||
Expect(zRankWithScore.Err()).NotTo(HaveOccurred())
|
||||
Expect(zRankWithScore.Result()).To(Equal(redis.RankScore{Rank: 1, Score: 2}))
|
||||
|
||||
zRankWithScore = client.ZRankWithScore(ctx, "zset", "three")
|
||||
Expect(zRankWithScore.Err()).NotTo(HaveOccurred())
|
||||
Expect(zRankWithScore.Result()).To(Equal(redis.RankScore{Rank: 2, Score: 3}))
|
||||
|
||||
zRankWithScore = client.ZRankWithScore(ctx, "zset", "four")
|
||||
Expect(zRankWithScore.Err()).To(HaveOccurred())
|
||||
Expect(zRankWithScore.Err()).To(Equal(redis.Nil))
|
||||
})
|
||||
|
||||
It("should ZRem", func() {
|
||||
err := client.ZAdd(ctx, "zset", redis.Z{Score: 1, Member: "one"}).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -5008,6 +5033,31 @@ var _ = Describe("Commands", func() {
|
||||
Expect(zRevRank.Val()).To(Equal(int64(0)))
|
||||
})
|
||||
|
||||
It("should ZRevRankWithScore", func() {
|
||||
err := client.ZAdd(ctx, "zset", redis.Z{Score: 1, Member: "one"}).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = client.ZAdd(ctx, "zset", redis.Z{Score: 2, Member: "two"}).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = client.ZAdd(ctx, "zset", redis.Z{Score: 3, Member: "three"}).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
zRevRankWithScore := client.ZRevRankWithScore(ctx, "zset", "one")
|
||||
Expect(zRevRankWithScore.Err()).NotTo(HaveOccurred())
|
||||
Expect(zRevRankWithScore.Result()).To(Equal(redis.RankScore{Rank: 2, Score: 1}))
|
||||
|
||||
zRevRankWithScore = client.ZRevRankWithScore(ctx, "zset", "two")
|
||||
Expect(zRevRankWithScore.Err()).NotTo(HaveOccurred())
|
||||
Expect(zRevRankWithScore.Result()).To(Equal(redis.RankScore{Rank: 1, Score: 2}))
|
||||
|
||||
zRevRankWithScore = client.ZRevRankWithScore(ctx, "zset", "three")
|
||||
Expect(zRevRankWithScore.Err()).NotTo(HaveOccurred())
|
||||
Expect(zRevRankWithScore.Result()).To(Equal(redis.RankScore{Rank: 0, Score: 3}))
|
||||
|
||||
zRevRankWithScore = client.ZRevRankWithScore(ctx, "zset", "four")
|
||||
Expect(zRevRankWithScore.Err()).To(HaveOccurred())
|
||||
Expect(zRevRankWithScore.Err()).To(Equal(redis.Nil))
|
||||
})
|
||||
|
||||
It("should ZScore", func() {
|
||||
zAdd := client.ZAdd(ctx, "zset", redis.Z{Score: 1.001, Member: "one"})
|
||||
Expect(zAdd.Err()).NotTo(HaveOccurred())
|
||||
|
Reference in New Issue
Block a user