在多台服务器上部署redis
我的 Web 应用程序使用 Redis 作为主数据库。它的性能非常好。这时候我的数据库太大了,我想添加一些新的服务器来存储。但我仍然停留在如何稳定且易于备份地分发的解决方案上。
大家有什么想法吗?
多谢!
My web application is using redis for the main database. It's very nice in performance. At this time, my database is too big and I want to add some new servers for storage. But I still stuck in the solution how to distribute in stable and easy to backup.
Everyone has any ideas?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我了解,redis 本身没有内置的自动方法来执行此操作(并且很难实现通用方法,因为它取决于您的应用程序将如何处理这些数据),您必须自己执行此操作(或在驱动程序中执行此操作,例如ruby 驱动程序确实如此)。
我认为你最好的选择是把这个逻辑放在你的应用程序中,在不了解你的应用程序的情况下很难准确地说,但你可以决定你的 ids 的第一部分决定密钥将存储在哪个 Redis 服务器上。
ruby 驱动程序只是尝试在服务器之间分发密钥,或者从密钥名称中获取服务器索引(如果进行了相应的格式化)(快速浏览一下代码后,类似于“{server_id}mykey”)
[编辑]
可能的解决方案:
- https://github.com/gmr/mredis
From what I understand there is no automatic way of doing this built into redis itself (and it's hard to implementa generic way since it depends what your application will do with these data), you have to do this yourself (or in the driver like the ruby driver does).
I think your best bet is to put that logic in your application, without any knowledge of your application it is hard to say precisely but you may decide that the first part of your ids decide which redis server the key will be stored.
The ruby driver simply try to distribute the keys among the servers or takes the server index from the key name if formatted accordingly (something like "{server_id}mykey" after a quick glance at the code)
[Edit]
Possible solution:
- https://github.com/gmr/mredis
你没有提到你使用哪种语言。如果是 Ruby,则驱动程序具有 客户端分片解决方案,解决了很多问题。 antirez 正在研究 Redis 的集群解决方案,但尚未完成。
但客户端分片和 Redis 集群都无法解决所有问题。例如,如果您需要对集合进行并集和交集,则无法执行此操作,除非两个集合碰巧驻留在同一个分片中(我相信 Redis 集群将有一些方法来处理此问题,但不会自动)。
还有一个解决方案是 Redis 磁盘存储,但就像集群一样,它还没有完成。磁盘存储意味着您可以将数据集增长到大于 RAM,并使用复制来扩展读取。
You don't mention which language you use. If it's Ruby then the driver has a client side sharding solution, which solves many problems. antirez is working on a cluster solution for Redis, but it is still unfinished.
Neither client side sharding nor Redis cluster can solve every problem though. If you, for example, need to do unions and intersections of sets you can't do that unless both sets happen to reside in the same shard (I believe Redis cluster will have some means to handle this, but not automatically).
Yet another solution is Redis diskstore, but just like the clustering it is not yet finished. Diskstore would mean that you can grow your dataset larger than RAM, and use replication to scale reads.