Skip to content

Commit

Permalink
fix:zverank return error (OpenAtomFoundation#2763)
Browse files Browse the repository at this point in the history
* fix:zverank return error

---------

Co-authored-by: chejinge <[email protected]>
  • Loading branch information
chejinge and brother-jin committed Aug 1, 2024
1 parent 73e66ec commit 6a6f71f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/storage/src/redis_zsets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ Status RedisZSets::ZRevrank(const Slice& key, const Slice& member, int32_t* rank
ZSetsScoreKey zsets_score_key(key, version, std::numeric_limits<double>::max(), Slice());
KeyStatisticsDurationGuard guard(this, key.ToString());
rocksdb::Iterator* iter = db_->NewIterator(read_options, handles_[2]);
for (iter->SeekForPrev(zsets_score_key.Encode()); iter->Valid() && left >= 0; iter->Prev(), --left, ++rev_index) {
for (iter->SeekForPrev(zsets_score_key.Encode()); iter->Valid() && left > 0; iter->Prev(), --left, ++rev_index) {
ParsedZSetsScoreKey parsed_zsets_score_key(iter->key());
if (parsed_zsets_score_key.member().compare(member) == 0) {
found = true;
Expand Down
28 changes: 28 additions & 0 deletions tests/integration/zset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,34 @@ var _ = Describe("Zset Commands", func() {
}}))
})

It("should ZREVRANK", func() {
err := client.ZAdd(ctx, "key", redis.Z{Score: 100, Member: "a1b2C3d4E5"}).Err()
Expect(err).NotTo(HaveOccurred())

err = client.Del(ctx, "key").Err()
Expect(err).NotTo(HaveOccurred())

err = client.ZAdd(ctx, "key", redis.Z{Score: 101, Member: "F6g7H8i9J0"}).Err()
Expect(err).NotTo(HaveOccurred())

rank, err := client.ZRank(ctx, "key", "a1b2C3d4E5").Result()
Expect(err).To(Equal(redis.Nil))
Expect(rank).To(Equal(int64(0)))

revrank, err := client.ZRevRank(ctx, "key", "a1b2C3d4E5").Result()
Expect(err).To(Equal(redis.Nil))
Expect(revrank).To(Equal(int64(0)))

scanResult, cursor, err := client.ZScan(ctx, "key", 0, "", 10).Result()
Expect(err).NotTo(HaveOccurred())
Expect(cursor).To(Equal(uint64(0)))
Expect(scanResult).To(Equal([]string{"F6g7H8i9J0", "101"}))

card, err := client.ZCard(ctx, "key").Result()
Expect(err).NotTo(HaveOccurred())
Expect(card).To(Equal(int64(1)))
})

//It("should ZRandMember", func() {
// err := client.ZAdd(ctx, "zset", redis.Z{Score: 1, Member: "one"}).Err()
// Expect(err).NotTo(HaveOccurred())
Expand Down

0 comments on commit 6a6f71f

Please sign in to comment.