Redis learning


1 basic content of redis

1.1 data type of redis

character string
Hash table
Ordered set

1.2 data storage mode of redis cluster

1.2.1 single node

1.2.2 master / slave mode

a) A master can have multiple slaves
b) Under the default configuration, the master node can read and write, while the slave node can only read and write
c) Do not modify the configuration to enable the slave node to support write operations, which is meaningless. The first reason is that the data written will not be synchronized to other nodes; second, when the master node modifies the same data, the data of the slave node will be overwritten
d) If the slave node is hung, it will not affect the read and write of other slave nodes and master nodes. After restarting, the data will be synchronized from the master node
e) After the master node is hung, the read of the slave node will not be affected. Redis will no longer provide the write service. After the master node is started, redis will provide the write service again.
f) After the master node is hung, the slave node will not re select a master node
If there is a password, when the master node sets the password:
The client needs a password to access the master; a password is required to start the slave, which can be configured in the configuration; a password is not required for the client to access the slave

3.2.3 sentinel mode

Sentinel mode:
a) Sentinel mode is based on master-slave mode. If there is only one redis node, sentinel has no meaning;
b) When the master node is hung, sentinel will select one of the slave nodes as the master and modify their configuration files. Other slave configuration files will also be modified. For example, the slaveof attribute will point to the new master;
c) When the master node restarts, it will no longer be a master, but as a slave to receive the synchronization data of the new master node;
d) Sentinel is also a process that may hang up. Therefore, sentinel will start several processes to form a sentinel cluster;
e) When the master-slave mode configures the password, sentinel will also change the configuration information to the configuration file synchronously, so don’t worry about it;
f) A sentinel or sentinel cluster can manage multiple master-slave redis;
g) It is better not to deploy sentinel on the same machine as redis. Otherwise, when the server of redis is hung up, sentinel will also hang up;
h) The redis cluster monitored by sentinel will define a master name, which represents the master redis of the redis cluster;
When using sentinel mode, the client does not directly connect to redis, but connects to the IP and port of sentinel. Sentinel provides the specific implementation of redis that can provide services. In this way, when the master node is down, sentinel will perceive and provide the new master node to the user.
Sentinel mode can basically meet the needs of general production, with high availability. However, when the amount of data is too large to be stored in one server, the master-slave mode or sentinel mode can not meet the requirements. At this time, the stored data needs to be partitioned and stored in multiple redis instances.

3.2.4 cluster mode

The emergence of cluster is to solve the problem of limited capacity of single redis. Redis data is allocated to multiple machines according to certain rules. cluster:
Cluster can be said to be a combination of sentinel and master-slave mode. Through cluster, master-slave and master-slave reselection can be realized. Therefore, if two copies and three partitions are configured, six redis instances are required.
Because redis data is allocated to different machines in the cluster according to certain rules, when the amount of data is too large, new machines can be added to expand the capacity
This mode is suitable for large amount of data cache requirements, when the amount of data is not large, use sentinel.

Recommended Today

Summary of recent use of gin

Recently, a new project is developed by using gin. Some problems are encountered in the process. To sum up, as a note, I hope it can help you. Cross domain problems Middleware: func Cors() gin.HandlerFunc { return func(c *gin.Context) { //Here you can use * or the domain name you specify c.Header(“Access-Control-Allow-Origin”, “*”) //Allow header […]