You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by tw...@apache.org on 2025/05/13 06:09:58 UTC
(kvrocks) branch unstable updated: fix(zset): crash in ZRANDMEMBER for non-existent keys (#2982)
This is an automated email from the ASF dual-hosted git repository.
twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new 8206262f6 fix(zset): crash in ZRANDMEMBER for non-existent keys (#2982)
8206262f6 is described below
commit 8206262f676afaa6db540c32ceab022fa066fa8f
Author: weimeng <we...@163.com>
AuthorDate: Tue May 13 14:09:53 2025 +0800
fix(zset): crash in ZRANDMEMBER for non-existent keys (#2982)
Co-authored-by: weimeng <we...@didiglobal.com>
Co-authored-by: Twice <tw...@apache.org>
---
src/types/redis_zset.cc | 2 +-
tests/gocase/unit/type/zset/zset_test.go | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/types/redis_zset.cc b/src/types/redis_zset.cc
index bdc073642..333782b10 100644
--- a/src/types/redis_zset.cc
+++ b/src/types/redis_zset.cc
@@ -884,7 +884,7 @@ rocksdb::Status ZSet::RandMember(engine::Context &ctx, const Slice &user_key, in
std::string ns_key = AppendNamespacePrefix(user_key);
ZSetMetadata metadata(false);
rocksdb::Status s = GetMetadata(ctx, ns_key, &metadata);
- if (!s.ok()) return s.IsNotFound() ? rocksdb::Status::OK() : s;
+ if (!s.ok()) return s;
if (metadata.size == 0) return rocksdb::Status::OK();
return ExtractRandMemberFromSet<MemberScore>(
diff --git a/tests/gocase/unit/type/zset/zset_test.go b/tests/gocase/unit/type/zset/zset_test.go
index 334555992..90a495000 100644
--- a/tests/gocase/unit/type/zset/zset_test.go
+++ b/tests/gocase/unit/type/zset/zset_test.go
@@ -1324,6 +1324,10 @@ func basicTests(t *testing.T, rdb *redis.Client, ctx context.Context, enabledRES
}
createZset(rdb, ctx, "zset", z)
+ // ZRANDMEMBER key_not_exist
+ nilReply := rdb.Do(ctx, "ZRANDMEMBER", "key_not_exist").Val()
+ require.Equal(t, nil, nilReply)
+
// ZRANDMEMBER zset
str := rdb.Do(ctx, "ZRANDMEMBER", "zset").Val()
require.Contains(t, members, str.(string))