Spring integrates Redis for master-slave switching via Sentinel

Source: Internet
Author: User
Tags failover redis redis cluster redis server

Implement function Description:

Redis Server for Master-slaver-slaver-.... Master-slave configuration, through 2 sentinel failover failover, automatic switching, using the code can be directly used in the actual production environment.

Off Topic:

In general, such a deployment is sufficient to support the number of millions users, but if the number is too high, then the Master-slaver master of Redis will never be satisfied, so the Redis shard.

This article does not cover Redis shards, but if you do, you need to be careful to follow another article: Sentinel&jedis looks like a perfect solution, and that's half the story.

In the case of non-sharding, but our application uses Data shard-sharing, the data is distributed evenly across 4 different instances, each of which is deployed as a master-slave structure, Jedis does not provide

Sentinel-based Shardedjedispool, which means that in 4 shards, if one of the shards has a master-slave switch, the shardedjedispool used by the application cannot be notified, all

The operation on that Shard will fail. For a solution, refer to the Redis Sentinel-based Redis cluster (master-slave &sharding) high availability scheme

The code simulates multithreading to Set/get in Redis.

1. Maven Dependency Configuration [HTML]  View Plain  copy <dependency>       <groupId> org.springframework.data</groupid>           < artifactid>spring-data-redis</artifactid>            <version>1.4.1.RELEASE</version>       </dependency>        <dependency>            <groupId>redis.clients</groupId>           < artifactid>jedis</artifactid>           <version >2.6.2</version>       </dependency>        <dependency>           <groupId> Org.apache.commons</groupid>           <artifactId>commons-lang3</artifactId>            <version>3.3.2</version>   </dependency>  


2, Redis.properties   [plain] view Plain copy # Redis settings #sentinel1的IP和端口 im.hs.server.redis.sentinel1.host=192.168.62.154 im.hs.server.redis.sentinel1.port=26379 #sentinel2的IP和端口 im.hs.server.redis.sentinel2.host=192.168.62.153 IM.HS.S   erver.redis.sentinel2.port=26379 #sentinel的鉴权密码 Im.hs.server.redis.sentinel.mastername=155master Im.hs.server.redis.sentinel.password=hezhixiong #最大闲置连接数 im.hs.server.redis.maxidle=500 #最大连接数, Operation Redis will error when this connection is exceeded

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.