Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How run docker redis in cluster mode?

I started my redis docker container with:

docker run --privileged=true -p 6379:6379 --name TestRedis -d redis

When I try to use it from Spring Redis in clustered mode, I get the error:

Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR This instance has cluster support disabled
at redis.clients.jedis.Protocol.processError(Protocol.java:127)
at redis.clients.jedis.Protocol.process(Protocol.java:161)
at redis.clients.jedis.Protocol.read(Protocol.java:215)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
at redis.clients.jedis.Connection.getRawObjectMultiBulkReply(Connection.java:285)
at redis.clients.jedis.Connection.getObjectMultiBulkReply(Connection.java:291)
at redis.clients.jedis.Jedis.clusterSlots(Jedis.java:3376)
at redis.clients.jedis.JedisClusterInfoCache.discoverClusterNodesAndSlots(JedisClusterInfoCache.java:54)
at redis.clients.jedis.JedisClusterConnectionHandler.initializeSlotsCache(JedisClusterConnectionHandler.java:39)
at redis.clients.jedis.JedisClusterConnectionHandler.<init>(JedisClusterConnectionHandler.java:17)
at redis.clients.jedis.JedisSlotBasedConnectionHandler.<init>(JedisSlotBasedConnectionHandler.java:20)
at redis.clients.jedis.JedisSlotBasedConnectionHandler.<init>(JedisSlotBasedConnectionHandler.java:15)
at redis.clients.jedis.BinaryJedisCluster.<init>(BinaryJedisCluster.java:41)
at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:83)
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createCluster(JedisConnectionFactory.java:306)
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createCluster(JedisConnectionFactory.java:280)
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.afterPropertiesSet(JedisConnectionFactory.java:241)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 110 common frames omitted

What do I need to do to make it run as clustered?

like image 949
Don Rhummy Avatar asked Dec 19 '22 00:12

Don Rhummy


1 Answers

When you just run the redis Docker image as you're doing, it starts according to its Dockerfile and the built-in configuration, which does not have clustering turned on. The repository that Chris Tanner pointed you to uses the same base image, but adds the configuration to activate clustering. However, you will need to clone that repository and build the image, then you can run it. The repository has good instructions in the readme for how to build and run it, although the docker run leaves out the image name for some reason. Clone the repo, cd into it, and do this:

docker build -t testredis/redis-cluster .
docker run -i -t -p 7000:7000 -p 7001:7001 -p 7002:7002 -p 7003:7003 -p 7004:7004 -p 7005:7005 -p 7006:7006 -p 7007:7007 testredis/redis-cluster

That will have the cluster running, and you can point your client to it on port 7000.

like image 179
Masonoise Avatar answered Dec 28 '22 06:12

Masonoise