phpRedis migration to cluster and consistent hashing

2.5k views Asked by At

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.

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?

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

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

I am new to redis so please provide some advice

Thanks

1

There are 1 answers

0
Jya On BEST ANSWER

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

Hi,

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 does not currently support Redis Cluster.

Addressing your questions:

  • 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).

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

They have added support for Redis cluster now https://github.com/phpredis/phpredis/blob/feature/redis_cluster/cluster.markdown#readme