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

目前NewLife.Redis支持 Redis Cluster 下使用批量命令吗 #46

Closed
leegkon opened this issue Feb 9, 2020 · 3 comments
Closed

目前NewLife.Redis支持 Redis Cluster 下使用批量命令吗 #46

leegkon opened this issue Feb 9, 2020 · 3 comments

Comments

@leegkon
Copy link

leegkon commented Feb 9, 2020

如题,目前NewLife.Redis支持 Redis Cluster 下使用批量命令吗,如mget 或 pipeline

@nnhy
Copy link
Member

nnhy commented Feb 9, 2020

cluster本身就不支持批量命令如mget等。
因为cluster是根据key进行哈希分片存储,某次请求一批keys,可能并不在同一个分片上面,因此不支持。

实际经验里面,我们不适用cluster,而是自己手工分片。例如48实例,就有一个Redis[48]的数组,100亿数据key计算哈希后,得到具体redis,再进行各种操作。如果需要批量获取,那就先对每一个key记性哈希计算,然后分组,同一组的key落在同一个redis上,可以使用mget,48个组可以并行处理,也就是并行执行48个mget,然后合并结果。

@leegkon
Copy link
Author

leegkon commented Feb 10, 2020

多谢大石头,您说的很对,cluster默认是不支持mget的。
但类似Jredis之类的客户端 通过smart client的形式间接支持了mget的实现,对于调用方无需了解其内部细节,目前在.net方面暂时还没有好的支持,不知道newlife 有没有打算支持这一需求?

@nnhy
Copy link
Member

nnhy commented Jul 10, 2020

可以考虑根据key提前分组到各个client,然后对它们使用mget,我们在实际项目中就是这么做的。不过没有用cluster,而是自己认为把数据key分摊到多组redis实例上。100亿数据平均分摊到48组。

@nnhy nnhy closed this as completed Jul 10, 2020
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

No branches or pull requests

2 participants