Redis Cluster Basic Redis Operations Example:
jediscluster jc = null; @Before public void before () { set Jedis operation scenario for master-slave switching:
jediscluster jc = null; @Before public void before () { set output:
Null14306631098571430663110860......redis.clients.jedis.exceptions.jedisclustermaxredirectionsexception:too Many Cluster redirections? At Redis.clients.jedis.JedisClusterCommand.runWithRetries (jedisclustercommand.java:37) at Redis.clients.jedis.JedisClusterCommand.runWithRetries (jedisclustercommand.java:70) ... Redis.clients.jedis.exceptions.JedisClusterException:CLUSTERDOWN the cluster is down at Redis.clients.jedis.Protocol . Processerror (protocol.java:111) at redis.clients.jedis.Protocol.process (protocol.java:138) ... Cluster is recovered! Downtime lasted 7089 ms14306631378971430663146602 ...
Pom.xml:
<properties> <junit.version>4.11</junit.version > <assertj.version>1.7.0</assertj.version> </properties> <dependencies> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.6.2</version> </ dependency> <dependency> <groupId>junit</groupId> <artifactid>junit</artifactid> <version>${junit.version}</version> <scope>test</scope> </dependency> <!-- assertj --> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>${assertj.version}</version> <scope>test</scope> </dependency> </dependencies>
Reference:
Https://github.com/xetorthio/jedis
Problem:
-
hostandport only need to specify a host IP and port? All the others are directly rediscluster, right?
excerpt from http://redis.io/topics/cluster-tutorial
3 Startup_nodes = [4 {: host = "127.0.0.1",:p ort = 7000}, 5 {: host = "127.0.0.1",:p ort =& Gt 7001} 6] The startup nodes don ' t need to being all the nodes of the cluster. The important thing is, at least one node is reachable. Also Note that Redis-rb-cluster updates this list of startup nodes as soon as it's able to connect with the first node. You should expect such a behavior with any other serious client.
Redis Cluster Jedis client example