Skip to content

Commit

Permalink
fix(kv): zset rank (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
caojiajun committed Jan 15, 2025
1 parent 46f7d92 commit dd033ef
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.netease.nim.camellia.redis.proxy.upstream.kv.meta.EncodeVersion;
import com.netease.nim.camellia.redis.proxy.upstream.kv.meta.KeyMeta;
import com.netease.nim.camellia.redis.proxy.upstream.kv.meta.KeyType;
import com.netease.nim.camellia.redis.proxy.util.Utils;
import com.netease.nim.camellia.tools.utils.BytesKey;
import com.netease.nim.camellia.tools.utils.Pair;

Expand Down Expand Up @@ -177,7 +176,8 @@ private Pair<Integer, ZSetTuple> zrankFromKv(int slot, KeyMeta keyMeta, byte[] k
}
startKey = keyValue.getKey();
if (Arrays.equals(keyDesign.decodeZSetMemberBySubKey2(startKey, key), member.getKey())) {
return new Pair<>(index, new ZSetTuple(member, Utils.bytesToDouble(keyValue.getValue())));
double score = keyDesign.decodeZSetScoreBySubKey2(keyValue.getKey(), key);
return new Pair<>(index, new ZSetTuple(member, score));
}
index++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ private Pair<Integer, ZSetTuple> zrevrankFromKv(int slot, KeyMeta keyMeta, byte[
}
startKey = keyValue.getKey();
if (Arrays.equals(keyDesign.decodeZSetMemberBySubKey2(startKey, key), member.getKey())) {
return new Pair<>(index, new ZSetTuple(member, Utils.bytesToDouble(keyValue.getValue())));
double score = keyDesign.decodeZSetScoreBySubKey2(keyValue.getKey(), key);
return new Pair<>(index, new ZSetTuple(member, score));
}
index++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class TestAll {

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

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

int stringVersion = 0;
int hashVersion = 0;
int zsetVersion = 0;
int setVersion = 0;
int zsetVersion = 0;
boolean zsetMscore = true;

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

new Thread(() -> {
while (true) {
if (zsetVersion == 0) {
TestZSetV0.testZSet(template);
} else if (zsetVersion == 1) {
TestZSetV1.testZSet(template);
if (zsetVersion == 0 || zsetVersion == 1) {
TestZSetV0.testZSet(template, zsetMscore);
}
sleep(100);
}
Expand Down
Loading

0 comments on commit dd033ef

Please sign in to comment.