Skip to content

Commit dd033ef

Browse files
committed
fix(kv): zset rank (#372)
1 parent 46f7d92 commit dd033ef

File tree

4 files changed

+156
-102
lines changed

4 files changed

+156
-102
lines changed

camellia-redis-proxy/camellia-redis-proxy-core/src/main/java/com/netease/nim/camellia/redis/proxy/upstream/kv/command/zset/ZRankCommander.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.netease.nim.camellia.redis.proxy.upstream.kv.meta.EncodeVersion;
1818
import com.netease.nim.camellia.redis.proxy.upstream.kv.meta.KeyMeta;
1919
import com.netease.nim.camellia.redis.proxy.upstream.kv.meta.KeyType;
20-
import com.netease.nim.camellia.redis.proxy.util.Utils;
2120
import com.netease.nim.camellia.tools.utils.BytesKey;
2221
import com.netease.nim.camellia.tools.utils.Pair;
2322

@@ -177,7 +176,8 @@ private Pair<Integer, ZSetTuple> zrankFromKv(int slot, KeyMeta keyMeta, byte[] k
177176
}
178177
startKey = keyValue.getKey();
179178
if (Arrays.equals(keyDesign.decodeZSetMemberBySubKey2(startKey, key), member.getKey())) {
180-
return new Pair<>(index, new ZSetTuple(member, Utils.bytesToDouble(keyValue.getValue())));
179+
double score = keyDesign.decodeZSetScoreBySubKey2(keyValue.getKey(), key);
180+
return new Pair<>(index, new ZSetTuple(member, score));
181181
}
182182
index++;
183183
}

camellia-redis-proxy/camellia-redis-proxy-core/src/main/java/com/netease/nim/camellia/redis/proxy/upstream/kv/command/zset/ZRevRankCommander.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ private Pair<Integer, ZSetTuple> zrevrankFromKv(int slot, KeyMeta keyMeta, byte[
192192
}
193193
startKey = keyValue.getKey();
194194
if (Arrays.equals(keyDesign.decodeZSetMemberBySubKey2(startKey, key), member.getKey())) {
195-
return new Pair<>(index, new ZSetTuple(member, Utils.bytesToDouble(keyValue.getValue())));
195+
double score = keyDesign.decodeZSetScoreBySubKey2(keyValue.getKey(), key);
196+
return new Pair<>(index, new ZSetTuple(member, score));
196197
}
197198
index++;
198199
}

camellia-tests/camellia-redis-proxy-tests/src/main/java/com/netease/nim/camellia/tests/redis/proxy/kv/TestAll.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class TestAll {
1313

1414
public static void main(String[] args) {
1515
String url = "redis://[email protected]:6381";
16+
// String url = "redis://@127.0.0.1:6379";
1617

1718
CamelliaRedisEnv redisEnv = new CamelliaRedisEnv.Builder()
1819
.jedisPoolFactory(new JedisPoolFactory.DefaultJedisPoolFactory(new JedisPoolConfig(), 6000))
@@ -24,8 +25,9 @@ public static void main(String[] args) {
2425

2526
int stringVersion = 0;
2627
int hashVersion = 0;
27-
int zsetVersion = 0;
2828
int setVersion = 0;
29+
int zsetVersion = 0;
30+
boolean zsetMscore = true;
2931

3032
for (int i = 0; i<threads; i++) {
3133
new Thread(() -> {
@@ -41,10 +43,8 @@ public static void main(String[] args) {
4143

4244
new Thread(() -> {
4345
while (true) {
44-
if (zsetVersion == 0) {
45-
TestZSetV0.testZSet(template);
46-
} else if (zsetVersion == 1) {
47-
TestZSetV1.testZSet(template);
46+
if (zsetVersion == 0 || zsetVersion == 1) {
47+
TestZSetV0.testZSet(template, zsetMscore);
4848
}
4949
sleep(100);
5050
}

0 commit comments

Comments
 (0)