Single-machine moderedis
is very simple, you only need to start a single node, and the installation process does not take more than 5 minutes.
Test simple commands through redis-benchmark
, QPS
can reach more than 10w
, I have to say it is very amazing.
The problem with stand-alone mode is also very obvious. Lack of high availability mechanism!
If the redis
process dies, the process can only penetrate into the underlying database, which is very dangerous for the business. If you use redis
as data storage, the situation will be more serious and data may even be lost.
So the most basic redis
deployment will add one or more slave
(now called replication
).
When a problem occurs with the master redis
, you can choose a slave
to take over.
It is a pity that this mode is the same as the traditional MySQL
master-slave mode. It is more painful to switch and requires the help of external tools, such as keepalived
and other assistance. The difficulty of switching, deployment and maintenance skyrocketed.
keepalived
is a high-availability solution based on the VRRP
protocol, which achieves high availability through IP drift. It can be seen from the description that it requires the participation of the network administrator, which is contrary to our lightweight redis
.
Sentinel mode uses additional processes to replace the function of keepalived
to judge the viability of the redis
process. In sentry mode, once the master node goes down, the slave node can come back at any time as the backup of the master node.
But one of the biggest problems with the sentinel mode is that there are too many sentinels, which requires at least 3 nodes.
When arbitrating redis
, n/2 1
nodes are required to vote to confirm. This is also the general practice of distributed systems (quorum). Similar to Zookeeper
, it is very appropriate to make an odd number of sentinel nodes.
Sentinel mode can detect multiple clusters at the same time through sentinel monitor
configuration. It is relatively easy to use when the number of clusters is moderate.
But the sentinel mode has many hidden pitfalls, such as the startup of the sentinel, which can only run normally when the master
is alive; in addition, if your redis
configuration When RENAME
is used in the file to block some dangerous commands, Sentinel cannot be started.
When the client connects to redis
, it can no longer directly connect to the instance of redis
. It needs to make a circle from the sentinel in order to obtain some change information.
Cluster mode can be said to be the most elegant method here. You only need to deploy multiple peer redis
nodes, and then use client commands to group them.
ip=192.169.0.23 ./bin/redis-cli --cluster create $ip:7001 $ip:7002 $ip:7003 $ip:7004 $ip:7005 $ip:7006 --cluster-replicas 1
It also requires a lot of nodes. It generally uses 6 nodes, three masters and three slaves. Once the number of nodes exceeds 10, collaboration becomes less flexible, and therefore the storage and performance limits of a single cluster are quickly reached.
Some disadvantages of cluster mode are very hidden. Its server node is very stable, but some commands will seriously affect performance. For example, mget
, pipeline
, etc. They need to distribute requests to multiple nodes for execution and then aggregate them. The more nodes there are, the lower the performance.
The above is the detailed content of What are the Redis cluster modes and what are their advantages?. For more information, please follow other related articles on the PHP Chinese website!