Redis master Copy and Sentinel's configuration and role in the Java class library

Redis is a high -performance, support for persistent key value storage database.It uses the master and slave copy and Sentinel to provide the function of high availability and fault transfer.This article will introduce the configuration and role of Redis Corporation and SENTINEL in the Java class library, and provide the corresponding Java code example. Redis master -slave replication means that the data is reduced from a Redis server (main server) to multiple Redis servers (from the server) to achieve the redundant backup and read and write separation of the data.The configuration steps for the master and slave replication are as follows: 1. Configure the main server: First, set the `SLAVEOF No One` in the configuration file of the main server, indicating that the server is the main server. # redis.conf slaveof no one 2. Configure the server: Set the `SLAVEOF <Master-IP> <Master-Port>` in the configuration file of the server, and connect from the server to the main server. # redis.conf slaveof 127.0.0.1 6379 Through the above configuration, when the main server updates the data, it will copy the updated data to all from the server. From the server, the read request can be processed to share the load of the main server. Redis Sentinel is a tool for monitoring and managing Redis clusters.It provides high availability and fault recovery capabilities by monitoring the health state of the Redis instance and automatic fault transfer.The configuration steps of sentinel are as follows: 1. Configure Sentinel: Set the following parameters in the configuration file of Sentine: # sentinel.conf sentinel monitor <master-name> <master-ip> <master-port> <quorum> sentinel down-after-milliseconds <master-name> <timeout> sentinel failover-timeout <master-name> <timeout> -` <Master-name> `: The name of the main server specified by the monitoring. -` <Master-IP> `and` Master-Port> `: Specify the IP address and port of the main server. -` <quorum> `: Set the number of Sentinel nodes that determine whether the main server is down. -` <Timeout> `: Set the automatic fault transfer interval after the main server is down. 2. Start SENTINEL: Start the Sentinel through the following example examples: import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisSentinelPool; Set<String> sentinels = new HashSet<>(); sentinels.add("127.0.0.1:26379"); JedisSentinelPool jedisSentinelPool = new JedisSentinelPool("mymaster", sentinels); Jedis jedis = jedisSentinelPool.getResource(); -` Sentinels`: Set the IP address and port of Sentinel. -` mymaster`: the name of the main server specified by the monitoring. Through the above configuration, when the main server is down, the Sentiner will automatically move the failure, switch the role of the main server to one of the servers. In summary, the configuration and role of Redis' main copy and Sentinel in the Java library make Redis have the ability to have high availability and fault transfer.The main copy of the main copy and the load balancing by copying the data from the server, and the SENTINEL realizes the function of automatic transfer of the main server by monitoring and managing the Redis instance of the main server.These configurations and functions can be implemented in Java applications.