alibaba / jetcache

JetCache is a Java cache framework.
Apache License 2.0
4.96k stars 1.03k forks source link

feat: improve the performance of jedis batch commands. #873

Closed Roiocam closed 3 months ago

Roiocam commented 3 months ago

See: https://github.com/alibaba/jetcache/issues/865#issuecomment-2024561604

抽象了一下 pipeline 获取的接口,方便其他方法使用(getAll, delAll)

areyouok commented 3 months ago

redis cluster是不是不能很好的支持mget/mset?

Roiocam commented 3 months ago

redis cluster是不是不能很好的支持mget/mset?

这个不清楚,但是 JedisCluster 这个对象看起来是没有直接支持类似于 scan 那样多线程去拿的代码的,他的 mget 就是创建了一个:CommandObject, 里面有个 CommandArguments

最后在 ClusterCommandExecutor 里面这样执行的:

https://github.com/redis/jedis/blob/a02b2eb2dcb1c9ff31afe3fa91ebdd3fad8cad7e/src/main/java/redis/clients/jedis/executors/ClusterCommandExecutor.java#L90-L92

然后拿连接也是根据命令参数算出来 slot:

https://github.com/redis/jedis/blob/a02b2eb2dcb1c9ff31afe3fa91ebdd3fad8cad7e/src/main/java/redis/clients/jedis/providers/ClusterConnectionProvider.java#L100-L103

我思考的时候又想了下之前看 redis 源码的时候,Key 在不同的 SLOT 的时候,Redis Cluster 自身就会拒绝这个请求的:

https://github.com/redis/redis/blob/0b34396924eca4edc524469886dc5be6c77ec4ed/src/cluster.c#L1068-L1076

我试了一下,JedisCluster 也确实体现了这一点:

        ClusterCommandObjects clusterCommandObjects = new ClusterCommandObjects();
        CommandObject<List<String>> mget = clusterCommandObjects.mget("a", "b", "c", "d");
        System.out.println("mget");

Exception in thread "main" redis.clients.jedis.exceptions.JedisClusterOperationException: Keys must belong to same hashslot.