Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the redis-py module work with Redis in Cluster mode?

I'm trying to use redis-py with redis in cluster mode, but I can't get it to work. I see that redis-py-cluster works, but I have a preference for redis-py as I have been using it and it's a recommended client.

like image 437
pettinato Avatar asked Jan 31 '17 22:01

pettinato


People also ask

What is the difference between Redis and Redis cluster?

The Redis Cluster supports only one database - indicated if you have a big dataset - and Redis supports multiple databases. The Redis Cluster client must support redirection, while the client used for Redis doesn't need it.

How Redis works in cluster mode?

Redis Cluster provides a way to run a Redis installation where data is automatically sharded across multiple Redis nodes. Redis Cluster also provides some degree of availability during partitions, that is in practical terms the ability to continue the operations when some nodes fail or are not able to communicate.

How do I connect to a Redis cluster in Python?

To connect a python application to redis cluster we will use redis-py-cluster. Know more about redis-py-cluster here. All we need to do now is import RedisCLuster and define some configuration. Variable rc will now be capable to do all redis operations like exists() , expire() etc.


2 Answers

redis-py does not support cluster mode. Clustering has totally different architecture to serve the purpose of horizontal scalability. HA (High Availability) was not a priority in its design. Therefore you can not use one client for the other.

redis-py-cluster seem to have ongoing development / support, and it's based on redis.py. The client page you linked was not for redis cluster. "redis-py-cluster" is mentioned on redis cluster page (look for "Playing with the cluster"): https://redis.io/topics/cluster-tutorial

Asides from clustering, Redis has sentinel supported setup to provide HA, which redis-py does support.

like image 57
nafooesi Avatar answered Oct 03 '22 06:10

nafooesi


You can use redis-py in redis cluster, but as different keys are partitioned to different nodes, you need to compute (by crc16/crc32 hash function) which cluster handles which keys.

In order to fully utilize "cluster mode", where you don't care about keys' location, you need to implement "client side partitioning" and "query routing" which redis-py-cluster provides. (https://redis.io/topics/partitioning)

One major disadvantage of redis-py-cluster is that it does not provide a solution for the atomic operation in "pipeline + transaction"

like image 43
JUNPA Avatar answered Oct 03 '22 05:10

JUNPA