Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Mar 29, 2024

Conversation

Roiocam
Copy link
Contributor

@Roiocam Roiocam commented Mar 28, 2024

See: #865 (comment)

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

@Roiocam Roiocam marked this pull request as draft March 28, 2024 07:48
@Roiocam Roiocam marked this pull request as ready for review March 28, 2024 08:05
@areyouok
Copy link
Collaborator

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

@Roiocam
Copy link
Contributor Author

Roiocam commented Mar 28, 2024

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.

@Roiocam Roiocam requested a review from areyouok March 29, 2024 01:57
@Roiocam Roiocam requested a review from areyouok March 29, 2024 05:44
@areyouok areyouok merged commit 54cd818 into alibaba:master Mar 29, 2024
2 checks passed
@Roiocam Roiocam deleted the perf-jedis-batch-comamnd branch March 29, 2024 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants