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 496f9d4ca fix(zset): wrong RESP reply in ZRANDMEMBER and ZMSCORE 
command (#2937)
496f9d4ca is described below

commit 496f9d4cabfac384371bef20191e1b24d62bef52
Author: weimeng <[email protected]>
AuthorDate: Wed May 7 22:35:31 2025 +0800

    fix(zset): wrong RESP reply in ZRANDMEMBER and ZMSCORE command (#2937)
    
    Co-authored-by: weimeng <[email protected]>
---
 src/commands/cmd_zset.cc                 |  4 ++--
 tests/gocase/unit/type/zset/zset_test.go | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/commands/cmd_zset.cc b/src/commands/cmd_zset.cc
index 99285a625..49fb1f7a5 100644
--- a/src/commands/cmd_zset.cc
+++ b/src/commands/cmd_zset.cc
@@ -1115,7 +1115,7 @@ class CommandZMScore : public Commander {
         }
       }
     }
-    *output = conn->MultiBulkString(values);
+    *output = Array(values);
     return Status::OK();
   }
 };
@@ -1451,7 +1451,7 @@ class CommandZRandMember : public Commander {
     }
 
     if (no_parameters_)
-      *output = s.IsNotFound() ? conn->NilString() : 
redis::BulkString(result_entries[0]);
+      *output = s.IsNotFound() ? conn->NilString() : result_entries[0];
     else
       *output = Array(result_entries);
     return Status::OK();
diff --git a/tests/gocase/unit/type/zset/zset_test.go 
b/tests/gocase/unit/type/zset/zset_test.go
index 26fb2cd8d..334555992 100644
--- a/tests/gocase/unit/type/zset/zset_test.go
+++ b/tests/gocase/unit/type/zset/zset_test.go
@@ -1295,6 +1295,22 @@ func basicTests(t *testing.T, rdb *redis.Client, ctx 
context.Context, enabledRES
 
        })
 
+       t.Run(fmt.Sprintf("ZMSCORE - %s", encoding), func(t *testing.T) {
+               rdb.Del(ctx, "zset")
+               createZset(rdb, ctx, "zset", []redis.Z{
+                       {Score: 1, Member: "a"},
+                       {Score: 2, Member: "b"},
+                       {Score: 3, Member: "c"},
+               })
+
+               require.Equal(t, int64(1), int64(rdb.ZMScore(ctx, "zset", 
"a").Val()[0]))
+               require.Equal(t, int64(2), int64(rdb.ZMScore(ctx, "zset", 
"b").Val()[0]))
+
+               res := rdb.ZMScore(ctx, "zset", "a", "b").Val()
+               require.Equal(t, int64(1), int64(res[0]))
+               require.Equal(t, int64(2), int64(res[1]))
+       })
+
        t.Run(fmt.Sprintf("ZRANDMEMBER without scores - %s", encoding), func(t 
*testing.T) {
                // create a zset with 6 elements
                members := []string{"a", "b", "c", "d", "e", "f"}
@@ -1308,6 +1324,10 @@ func basicTests(t *testing.T, rdb *redis.Client, ctx 
context.Context, enabledRES
                }
                createZset(rdb, ctx, "zset", z)
 
+               // ZRANDMEMBER zset
+               str := rdb.Do(ctx, "ZRANDMEMBER", "zset").Val()
+               require.Contains(t, members, str.(string))
+
                // ZRANDMEMBER zset len(members)
                res := rdb.ZRandMember(ctx, "zset", len(members)).Val()
                sort.Strings(res)

Reply via email to