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