Redis Cluster Jedis Client Example

Source: Internet
Author: User
Tags redis cluster

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:

    1.  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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.