phpRedis 迁移到集群和一致性哈希 [英] phpRedis migration to cluster and consistent hashing

查看:74
本文介绍了phpRedis 迁移到集群和一致性哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在使用 PhpRedis 扩展,我们的代码是使用 PhpRedis 中的 Redis 类编写的.但是现在我们要迁移到redis集群了.

We are currently using PhpRedis extension and our code is written using the class Redis from the PhpRedis. But now we are migrating to a redis cluster.

是否可以使用类Redis连接到redis集群?还是我们需要重新编写代码并使用 RedisArray 类?

Is it possible to use the Class Redis to connect to redis cluster? or do we need to re-write our code and use the Class RedisArray?

我们也需要一致的散列.我们添加了这样的键 {user}:1 以便我们以后可以进行一致的散列.

We ll need to have consistent hashing too. We have added keys like this {user}:1 so we can do consistent hashing later.

主要问题是将使用 Redis 类编写的所有代码更改为 RedisArray.

main problem is taking all the code written using the class Redis and changing it to RedisArray.

我是 redis 新手,所以请提供一些建议

I am new to redis so please provide some advice

谢谢

推荐答案

这是来自 PHPredis Nicolas 的作者之一的电子邮件回复.我感谢他花时间回复我.

This is a email reply from one of the author of PHPredis Nicolas. I thank him for taking the time for replying to me.

我只想首先澄清 RedisArray 类没有为 Redis 集群提供客户端库.它使用一致性哈希将数据分发到一组独立的 Redis 节点,并提供一个通用接口,使开发人员不必自己编写分发层.

I just want to start by clarifying that the RedisArray class does not provide a client library for Redis Cluster. It uses consistent hashing to distribute data to a set of independent Redis nodes, and provides a common interface so that developers can avoid having to write the distribution layer themselves.

Phpredis 目前不支持 Redis 集群.

Phpredis does not currently support Redis Cluster.

解决您的问题:

  • It is possible to connect to 4 redis servers with RedisArray.
  • RedisArray provides consistent hashing and you can select which part of the key is to be used for the distribution.
  • The RedisArray class has a few limitations. In particular, multi-key commands (e.g. ZINTERSTORE) are mostly executed on one node, but some do offer integrated distribution (e.g. DEL, MGET).

要了解有关 RedisArray 类的更多信息,请参阅 GitHub 上的文档.

To learn more about the RedisArray class, please refer to the documentation on GitHub.

他们现在增加了对 Redis 集群的支持https://github.com/phpredis/phpredis/blob/feature/redis_cluster/cluster.markdown#readme

这篇关于phpRedis 迁移到集群和一致性哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆