REDIS installation and operation notes

Table of contents

1. Introduction to Redis... 1

Two, Redis deployment mode... 1

1. Stand-alone mode... 1

2. Master-slave mode... 2

3. Sentry Mode... 2

4. Cluster mode... 3

3. Redis deployment... 4

1. Stand-alone mode deployment... 4

2. Cluster mode (three masters and three slaves) deployment... 5

① Automatically build Redis three-master cluster script... 5

② Production environment Redis cluster... 6

③Configuration information taking 700 nodes as an example... 7

Four, Redis high availability... 7

Five, Redis data persistence... 8

Six, Redis common operation and maintenance operations... 9

a. Create a cluster... 9

b. Access to the cluster... 9

c. Start the Redis service of the node... 9

d. Close the Redis service of the node... 10

e. Check the cluster status... 10

f. Delete the slave node and rejoin the cluster... 10

g. Delete a master node... 11

h. Add a master node... 13

i. Other operations... 15

j. A master node of Redis hangs up... 16

k. A slave node of Redis hangs up... 17

Seven, Redis operation and maintenance notes... 18

1. View authorization code information... 18

2. Batch delete key. 18

1. Introduction to Redis

   Redis (Remote Dictionary Server) remote dictionary service is an open-source,  log-type, Key-Value database written in ANSI C language , supports network, can be memory-based or persistent , and provides APIs in multiple languages.

   Redis is a key-value storage system . Similar to Memcached, it supports relatively more value types for storage, including string (string), list ( linked list), set (collection), zset (sorted set -- ordered set) and hash (hash type). These data types support push/pop, add/remove, intersection, union, difference and richer operations, and these operations are atomic. On this basis, Redis supports sorting in various ways. Like Memcached, data is cached in memory to ensure efficiency. The difference is that Redis will periodically write updated data to disk or write modification operations to additional record files, and on this basis, master-slave (master-slave) synchronization is realized.

   Six characteristics of Redis: fast speed, extensive language support, persistence, multiple data structures, master-slave replication, high availability and distribution

Official Website: Download | Redis

2. Redis deployment mode

   Redis has several common deployment modes: stand-alone mode, master-slave mode, sentinel mode (sentinel), cluster mode (cluster), and third-party mode.

   1. Stand-alone mode

Redis single copy adopts a single Redis node deployment architecture. There is no backup node to synchronize data in real time. It does not provide data persistence and backup strategies. It is suitable for pure cache business scenarios that do not require high data reliability.

advantage:

① Simple structure and easy deployment.

②Cost-effective: There is no need for a backup node when the cache is used (the availability of a single instance can be guaranteed by supervisor or crontab). Of course, in order to meet the high availability of the business, a backup node can also be sacrificed, but only one instance provides external services at the same time, high performance.

shortcoming:

①The reliability of the data is not guaranteed.

② After the cache is used and the process is restarted, the data is lost. Even if there are spare nodes to solve the high availability, it still cannot solve the cache warm-up problem, so it is not suitable for businesses with high data reliability requirements.

③High performance is limited by the processing power of a single-core CPU (Redis is a single-thread mechanism), and the CPU is the main bottleneck, so it is suitable for scenarios with simple operation commands, less sorting, and fewer calculations. You can also consider using Memcached instead.

   2. Master-slave mode

Redis adopts a master-slave (multi-slave) deployment structure. Compared with a single copy, the biggest feature is real-time data synchronization between master and slave instances, and provides data persistence and backup strategies. The master-slave instance is deployed on different physical servers. According to the company's basic environment configuration, it can provide external services and read-write separation strategy at the same time.

advantage:

① High reliability: On the one hand, it adopts a dual-machine active-standby architecture, which can automatically switch between the active and standby when the main library fails, and promote the slave library to provide services for the main library to ensure the smooth operation of the service; on the other hand, enable data persistence A backup strategy with reasonable functions and configuration can effectively solve the problems of data misoperation and abnormal data loss.

②Read-write separation strategy: The slave node can expand the reading capability of the main library node, effectively coping with large concurrent read operations.

  

shortcoming:

①Failure recovery is complicated. If there is no RedisHA system (requires development), when the main database node fails, a slave node needs to be manually promoted to the master node, and the business party needs to be notified to change the configuration, and other slave database nodes need to copy the new one. For the main database node, the whole process requires human intervention, which is cumbersome.

②The writing ability of the main library is limited by a single machine, so fragmentation can be considered.

③ The storage capacity of the main library is limited by a single machine, so Pika can be considered.

④The disadvantages of native replication will be more prominent in the early version. For example, after Redis replication is interrupted, Slave will initiate psync. If the synchronization fails at this time, it will perform full synchronization. Millisecond or second-level stuttering; due to the COW mechanism, the main library memory overflows in extreme cases, and the program exits abnormally or crashes; the backup file generated by the main library node causes server disk IO and CPU (compression) resource consumption; GB-sized backup files lead to a surge in server export bandwidth and block requests. It is recommended to upgrade to the latest version.

   3. Sentry mode

Redis Sentinel is a native high-availability solution launched after version 2.8. Its deployment architecture mainly includes two parts: Redis Sentinel cluster and Redis data cluster. Among them, the Redis Sentinel cluster is a distributed cluster composed of several Sentinel nodes, which can realize fault discovery, automatic fault transfer, configuration center and client notification. The number of nodes of Redis Sentinel must satisfy an odd number of 2n+1 (n>=1).

advantage:

①Redis Sentinel cluster deployment is simple.

②It can solve the high-availability switching problem in Redis master-slave mode.

③It is very convenient to realize the linear expansion of Redis data nodes, easily break through the single-thread bottleneck of Redis itself, and can greatly meet the business needs of Redis with large capacity or high performance.

④ A set of Sentinel can be implemented to monitor a set of Redis data nodes or multiple sets of data nodes.

shortcoming:

①The deployment is more complicated than the Redis master-slave mode, and the understanding of the principle is more cumbersome.

② Waste of resources, the slave node in the Redis data node does not provide services as a backup node.

③Redis Sentinel is mainly aimed at the high-availability switching of the master node in the Redis data node. The failure judgment of the Redis data node is divided into two types: subjective offline and objective offline. For the Redis slave node, there is a subjective offline operation for the node. , and failover is not performed.

④ It cannot solve the problem of reading and writing separation, and it is relatively complicated to implement.

   4. Cluster mode

Redis Cluster is a Redis distributed cluster solution launched after version 3.0. It mainly solves the needs of Redis distributed aspects. For example, when encountering bottlenecks such as stand-alone memory, concurrency and traffic, Redis Cluster can play a good role in load balancing. the goal of. The minimum configuration of Redis Cluster cluster nodes is more than 6 nodes (3 masters and 3 slaves). The master node provides read and write operations, and the slave node is used as a backup node. It does not provide requests and is only used for failover. Redis Cluster uses virtual slot partitioning. All keys are mapped to 0 to 16383 integer slots according to the hash function. Each node is responsible for maintaining a part of the slots and the key-value data mapped by the slots.

advantage:

① No central structure.

②Data is distributed in multiple nodes according to slot storage, and data sharing between nodes can dynamically adjust data distribution.

③Scalability: It can be extended linearly to more than 1000 nodes, and nodes can be dynamically added or deleted.

④ High availability: When some nodes are unavailable, the cluster is still available. By adding Slave as a standby data copy, automatic failover of failure can be realized, status information is exchanged between nodes through the gossip protocol, and the role promotion from Slave to Master is completed by voting mechanism.

⑤ Reduce operation and maintenance costs and improve system scalability and availability.

shortcoming:

①Client implementation is complex, the driver requires the implementation of Smart Client, cache slots mapping information and update it in time, which increases the difficulty of development, and the immaturity of the client affects the stability of the business. At present, only JedisCluster is relatively mature, and the exception handling part is not perfect, such as the common "max redirect exception".

②The node will be blocked for some reason (the blocking time is greater than the clutser-node-timeout), and it will be judged to be offline. This kind of failover is unnecessary.

③The data is copied asynchronously, which does not guarantee the strong consistency of the data.

When multiple businesses use the same set of clusters, it is impossible to distinguish hot and cold data based on statistics, and the isolation of resources is poor, which is prone to mutual influence.

④Slave acts as a "cold standby" in the cluster, which cannot relieve the reading pressure. Of course, the utilization rate of Slave resources can be improved through the reasonable design of the SDK.

⑤ Key batch operation restrictions, such as using mset and mget currently only support batch operations on Keys with the same slot value. For Keys mapped to different slot values, because Keys does not support cross-slot queries, it is not friendly to perform operations such as mset, mget, and sunion.

⑥Key transaction operation support is limited, only supports multi-key transaction operations on the same node, when multiple keys are distributed on different nodes, the transaction function cannot be used.

⑦Key is the minimum granularity of data partitioning, and a large key-value object such as hash, list, etc. cannot be mapped to different nodes.

⑧Multiple database spaces are not supported, redis under a single machine can support up to 16 databases, and only one database space, namely db 0, can be used in cluster mode.

⑨The replication structure only supports one layer, and the slave node can only replicate the master node, and does not support nested tree replication structure.

   5. Third-party mode (less used)

   

3. Redis deployment

   1. Stand-alone mode deployment

    a. Download the required Redis version from the official website and decompress it

[root@centos7min3 opt]# wget http://download.redis.io/releases/redis-5.0.7.tar.gz

[root@centos7min3 opt]# tar xzf redis-5.0.7.tar.gz

b. Check and install gcc and tcl dependencies

[root@centos7min3 opt]# yum -y install gcc

[root@centos7min3 opt]# yum -y install tcl

c. compile

[root@centos7min3 redis-5.0.7]# make

If during make, Redis reports an error:

zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory

>① make MALLOC=libc

>② If you want to use jemalloc, just install jemalloc

$ yum install jemalloc

$ rpm -ql jemalloc

/usr/bin/jemalloc.sh

/usr/lib64/libjemalloc.so.1

or

https://github.com/jemalloc/jemalloc/releases/download/4.2.1/jemalloc-4.2.1.tar.bz2

$ tar xvf jemalloc-4.2.1.tar.bz2

$ cd jemalloc-4.2.1

$ ./configure --prefix=/usr/local/jemalloc

$ make && make install

make MALLOC=/usr/local/jemalloc/lib

d. Specify the installation path to install

[root@centos7min3 redis-5.0.7]# make PREFIX=/usr/local/redis install

e. Start the Redis service

[root@centos7min3 bin]# ./redis-server

or

[root@centos7min3 src]# ./redis-server

 

 

   2. Cluster mode (three masters and three slaves) deployment

The environment required for cluster construction: Redis cluster requires at least 3 nodes, because the voting fault tolerance mechanism requires more than half of the nodes to think that a node is hung up, so the 2 nodes cannot form a cluster. To ensure the high availability of the cluster, each node needs to have a slave node, that is, a backup node, so the Redis cluster needs at least 6 servers.

   Automatically build the Redis three-master cluster script

###采用源码包搭建redis cluster三主集群###
############################
#!/bin/bash

###在一台服务器上搭建redis三主集群: 192.168.16.17:7001、192.168.16.17:7002、192.168.16.17:7003
###Redis 的几种常见使用方式包括:
  #单机模式
  #主从模式
  #哨兵模式(sentinel)
  #集群模式(cluster)

echo "Please download the version of redis you need from http://download.redis.io/releases/"
## for example: redis-5.0.7.tar.gz

dir_package='/md5'
install_package=${dir_package}'/redis-5.0.4.tar.gz'
package_version='redis-5.0.4'

## decompress the install package
package_tar_name=${install_package##*/}
package_name=${package_tar_name%%.tar*}
tar zxvf ${package_tar_name} -C ${dir_package}/
chown -R root:root ${package_name}

## compile and install
cd ${dir_package}/${package_name}/
pwd   
make
make install

## create the config-files
cd ${dir_package}/${package_name}/
for (( i=7001;i<=7003;i++ ))
do
   mkdir -p cluster/${i}
   cp ${dir_package}/${package_name}/redis.conf   cluster/${i}/
   cp ${dir_package}/${package_name}/src/redis-server  cluster/${i}/
   cp ${dir_package}/${package_name}/src/redis-cli   cluster/${i}/
   sed -i "s/bind 127.0.0.1/bind 192.168.16.17/g" cluster/${i}/redis.conf
   sed -i "s/daemonize no/daemonize yes/g"  cluster/${i}/redis.conf
   sed -i "s/port 6379/port ${i}/g"    cluster/${i}/redis.conf
   #sed -i "s/# requirepass foobared/requirepass 1234***/g"   cluster/${i}/redis.conf   ##搭建集群时把它注释掉,搭建成功后恢复并重启redis服务
   sed -i "s/pidfile \\/var\\/run\\/redis_6379.pid/pidfile \\${dir_package}\\/${package_name}\\/cluster\\/${i}\\/redis_${i}.pid/g"  cluster/${i}/redis.conf
   sed -i "s/# cluster-enabled yes/cluster-enabled yes/g"  cluster/${i}/redis.conf
   sed -i "s/# cluster-config-file nodes-6379.conf/cluster-config-file \\${dir_package}\\/${package_name}\\/cluster\\/${i}\\/nodes-${i}.conf/g"  cluster/${i}/redis.conf
   sed -i "s/logfile \"\"/logfile \\${dir_package}\\/${package_name}\\/cluster\\/${i}\\/redis_${i}.log/g"   cluster/${i}/redis.conf
   sed -i "s/dir .\//dir \\${dir_package}\\/${package_name}\\/cluster\\/${i}/g"  cluster/${i}/redis.conf 
done 

## start the redis server with 3 different config-files
${dir_package}/${package_name}/cluster/7001/redis-server  ${dir_package}/${package_name}/cluster/7001/redis.conf
sleep 3s
${dir_package}/${package_name}/cluster/7002/redis-server  ${dir_package}/${package_name}/cluster/7002/redis.conf
sleep 3s
${dir_package}/${package_name}/cluster/7003/redis-server  ${dir_package}/${package_name}/cluster/7003/redis.conf
sleep 3s

for (( j=7001;j<=7003;j++ ))
do
  if [ `netstat -anp | grep ${j} | wc -l` -eq 0 ]
    then
      echo "redis ${j} started failed"
    else
      echo "redis ${j} started successfully"
  fi
done

## create redis cluster
## 建议手动创建redis集群,命令参考如下:
①  ##三主集群创建
##${dir_package}/${package_name}/cluster/7001/redis-cli --cluster  create 192.168.16.17:7001 192.168.16.17:7002 192.168.16.17:7003    
## Can I set the above configuration? (type 'yes' to accept):    ———— 你需要输入yes以保存集群的配置
②  ##三主三从集群创建
##${dir_package}/${package_name}/cluster/7001/redis-cli create 192.168.16.17:7001 192.168.16.17:7002 192.168.16.17:7003 192.168.16.17:7004 192.168.16.17:7005 192.168.16.17:7006  --cluster-replicas 1                              

## 访问集群
## ${dir_package}/${package_name}/cluster/7001/redis-cli -h 192.168.16.17 -p 7001 -c
## 如果设置了密码requirepass,需要重启redis服务(无需再建集群)才可以通过以下带密码参数的方式访问集群
## ${dir_package}/${package_name}/cluster/7001/redis-cli -h 192.168.16.17 -p 7001 -c -a '1234***'

## [root@centos7-min7 md5]# ps -ef | grep redis | grep -v grep | awk '{print $2}' | xargs kill -9

   ② Production environment Redis cluster

master node

corresponding slave node

192.168.0.3:7000

192.168.0.13:7005

192.168.0.2:7003

192.168.0.35:7001

192.168.0.14:7004

192.168.0.72:7002

redis node

Redis deployment location (disk space greater than 1T)

192.168.0.3:7000

/data/opt/redis-5.0.4

192.168.0.35:7001

/opt/redis/redis-5.0.4

192.168.0.72:7002

/data/redis/redis-5.0.4

192.168.0.2:7003

/data/opt/redis-5.0.4

192.168.0.14:7004

/data/opt/redis-5.0.4

192.168.0.13:7005

/data/opt/redis-5.0.4

  

 

③ Configuration information taking 7000 nodes as an example

[hjrypt@web redis-5.0.4]$ vi cluster/7000/redis.conf

bind 192.168.0.3

port 7000

daemonize yes

pidfile /data/opt/redis-5.0.4/cluster/7000/redis_7000.pid

logfile /data/opt/redis-5.0.4/cluster/7000/redis_7000.log

databases 16

#   save ""

save 900 1 - set RDB persistence mode

save 300 10

save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

dir ./

masterauth 1234*** ——This is automatically generated, you don’t need to add this when you configure it initially

requirepass 1234***

maxmemory 15G - set according to the actual memory

appendonly yes - set AOF persistence mode

appendfilename "appendonly.aof"

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

aof-use-rdb-preamble yes - enable RDB-AOF hybrid persistence

cluster-enabled yes

cluster-config-file nodes-7000.conf

cluster-node-timeout 15000

4. Redis High Availability

There are two common ways of Redis high availability:

  • Master-slave replication (Replication-Sentinel mode)

The master node (master) is responsible for reading and writing, and the slave node (slave) is responsible for reading. The operation of this system relies on three main mechanisms:

① When a master instance and a slave instance are connected normally, the master will send a series of command streams to keep the slave updated, so as to copy the changes of its own data set to the slave, including client writing, key expiration or being deleted. Eviction etc.

②When the connection between the master and the slave is disconnected, because of network problems, or the master-slave realizes that the connection has timed out, the slave reconnects to the master and will try to perform a partial resynchronization: this means that it will try to get Command stream lost during connection.

③When partial resynchronization cannot be performed, the slave will request full resynchronization. This would involve a more complex process, for example the master would need to create a snapshot of all the data, send it to the slave, and then continuously send a stream of commands to the slave as the dataset changes.

  • Redis cluster (Redis-Cluster mode) - master-slave cluster

The role of the redis cluster three-master three-slave configuration:

Isn't redis cluster a way to achieve high availability? Why does a node hang up affect the normal operation of the business?

That is because there is no slave node. If there is a slave node, the master node will automatically convert the slave node to the master node when there is a problem. The state of the cluster is not affected, so the business is not affected.

You don’t have a slave node now. If the master node hangs up, there will be problems with data storage, and the status of the cluster will be affected, which will naturally affect the normal operation of the business.

Five, Redis data persistence

Redis is an in-memory database, and the data is stored in memory, but we all know that the data in memory changes quickly and is prone to loss. Fortunately, Redis also provides us with persistence mechanisms, namely RDB (Redis DataBase) and AOF (Append Only File).

RDB: The RDB persistence mechanism is to perform periodic persistence on the data in Redis.

AOF: The AOF mechanism uses each write command as a log, and writes it into a log file in append-only mode. Because this mode is append-only, there is no disk addressing overhead, so it is very fast, a bit like binlog in Mysql.

RDB>

RDB has very little impact on the performance of Redis, because it just forks a child process for persistence when synchronizing data, and it is faster than AOF when restoring data.

RDBs are all snapshot files, which are generated every five minutes or longer by default, which means that the data in the five minutes between this synchronization and the next synchronization is likely to be lost. AOF loses up to one second of data, and the data integrity is up and down. In addition, when RDB generates a data snapshot, if the file is large, the client may pause for a few milliseconds or even a few seconds

AOF>

RDB generates snapshots every five minutes, but AOF is operated by a background thread fsync once a second, so at most one second of data will be lost.

When AOF operates on log files, it writes in an append-only manner. It only writes data in an appended manner, which naturally reduces a lot of disk addressing overhead. The writing performance is amazing, and the files are not easy to be damaged. .

AOF logs are recorded in a very readable way. This feature is suitable for emergency recovery of catastrophic data deletion. For example, the company's interns cleared all the data through flushall, as long as the background rewrites at this time It hasn't happened yet, you immediately copy an AOF log file, delete the last flushall command and you're done.

6. Redis common operation and maintenance operations

a. Create a cluster

Execute the following command on a master node to create a three-master and three-slave cluster

##${dir_package}/${package_name}/cluster/7001/redis-cli

create 192.168.16.17:7001 192.168.16.17:7002 192.168.16.17:7003 192.168.16.17:7004 192.168.16.17:7005 192.168.16.17:7006   --cluster-replicas 1

Execute the following command on a master node to create a three-master cluster

##${dir_package}/${package_name}/cluster/7001/redis-cli

create 192.168.16.17:7001 192.168.16.17:7002 192.168.16.17:7003

b. Access to the cluster

## ${dir_package}/${package_name}/cluster/7001/redis-cli -h 192.168.16.17 -p 7001 -c

## If the password requirepass is set, you need to restart the redis service (no need to build the cluster again) before you can access the cluster through the following methods with password parameters

## ${dir_package}/${package_name}/cluster/7001/redis-cli -h 192.168.16.17 -p 7001 -a 'QwE#7a8B' -c

  • cluster info
  • cluster nodes
  • cluster help

c. Start the Redis service of the node

[hjrypt@webdp redis-5.0.4]$ src/redis-server cluster/7000/redis.conf

d. Shut down the Redis service of the node

[hjrypt@webdp redis-5.0.4]$ src/redis-cli -h 192.168.0.3 -p 7000 -a '1234***' shutdown

e. Check the cluster status

[hjrypt@webdp ~]$ /data/opt/redis-5.0.4/src/redis-cli --cluster check 192.168.0.3:7000 -a '1234***

 

f. Delete the slave node and rejoin the cluster

Delete the Slave node in the fail state and join the cluster again through the previous corresponding master node

192.168.0.72: 7002 redis slave node hangs

① View cluster nodes cluster nodes

② Delete the fail node cluster help

cluster forget ID

Or ./redis-cli --cluster del-node 192.168.0.13:7005 nodeID

③ According to the corresponding master node (192.168.0.2:7003), rejoin the slave node (192.168.0.72:7002) into the redis cluster

src/redis-cli --cluster add-node --cluster-slave --cluster-master-id cc1...9cb3 192.168.0.72:7002 192.168.0.2:7003 -a '1234***'

 

g. Delete a master node

First extract all the slots of the master node to be deleted to other master nodes

View cluster details

Delete 6307 master node

 

h. Add a master node

./redis-cli add-node new_host:new_port existing_host:existing_port
( any node and port)
./redis-cli --cluster  add-node 192.168.142.128:7007 192.168.142.128:7000

 

Allocate space slots for newly joined nodes

[hjrypt@jiankong src]$ ./redis-cli --cluster reshard 192.168.0.2:7003 -a '1234***'

./redis-cli reshard 192.168.142.128:7007

Ask if you want to allocate how much from the original 1-16384 slots to the new master node. Here we allocate 4000 as an example and press Enter
Then it will ask you to assign the id to whose master node, we just copy this id here

Ask if you want to allocate space to this node from all the spaces or allocate me from a certain node, enter all here and press Enter to continue

Then you will be assigned a distribution plan, enter yes to start the distribution. complete ok

Let's look at the 7007 that has allocated 4000 space slots.

i. Other operations

Check cluster status:

[hjrypt@hjrhosts1250 src]$ ./redis-cli --cluster check 192.168.0.72:7002 -a '1234***'

Repair the cluster:

[hjrypt@hjrhosts1250 src]$ ./redis-cli --cluster fix 192.168.0.72:7002 -a '1234***'

Reshard slot information is generally required after deleting or adding the cluster master node

cluster info view hash slot information

[hjrypt@jiankong src]$ ./redis-cli --cluster reshard 192.168.0.92:7003 -a '1234***'

cluster nodes Check the redis node information, the slot allocation is very chaotic (as shown in the figure), you can consider the rebance cluster

  • before rebalance

[hjrypt@webdp src]$ ./redis-cli --cluster rebalance 192.168.0.2:7003 -a '1234***'

  • after rebalance

j. A master node of Redis hangs up

Processing method: shut down a REDIS master node 7006, wait for its corresponding slave node 7003 to be upgraded to the master node, then restart the 7006 node, access the cluster, and check the cluster status

[root@centos7-min7 7006]# /md5/redis-5.0.4/src/redis-server redis.conf

[root@centos7-min7 7006]# /md5/redis-5.0.4/src/redis-cli  -h 192.168.16.17 -p 7006

 

k. A slave node of Redis hangs up

> Pre-operation: Check the status of Redis cluster nodes, shut down one of the Redis slave node services, and receive Prometheus warning emails

① View cluster nodes cluster nodes

② Close a Redis slave node

src/redis-cli -h 192.168.0.72 -p 7002 -a ‘' shutdown

  • Repair operation: delete the fail node, and rejoin the slave node to the cluster according to the corresponding master-slave node relationship

①Delete fail node cluster help

cluster forget ID

② According to the corresponding master node (192.168.0.92:7003), rejoin the slave node (192.168.0.72:7002) into the Redis cluster

src/redis-cli --cluster add-node --cluster-slave --cluster-master-id cc1...9cb3 192.168.0.72:7002 192.168.0.92:7003 -a '1234***'

> Repair result: Redis cluster returned to normal

Seven, Redis operation and maintenance notes

Redis Reference Manual: Redis Tutorial | Novice Tutorial

1. View information

192.168.0.213:7005> smembers auth_token:MOP419375:300012004603

 

2. Delete keys in batches

There is no command to delete key directly according to regular expression in redis , only del key1 key2... command

But there are commands in redis to get keys through regular expressions: keys "regular expressions"

[root@localhost redis7001]# redis-cli -h 192.169.1.71 -p 7001 -a 123456 keys em* | xargs -r -t -n1 ./redis-cli -h 192.169.1.71 -p 7001 -a 123456 del

Supplement 1: The parameter -r must be added after the xargs command, otherwise when the number of keys is 0, an error (error) ERR wrong number of arguments for 'del' command will be reported

Supplement 2: The parameter -n1 must be added after the xargs command, otherwise when the number of keys in the cluster is greater than 1, an error (error) CROSSSLOT Keys in request don't hash to the same slot may be reported

Supplement 3: It is also possible not to add -t. Adding -t will output the deleted content each time. If it is not added, it will not output the deleted content, but it will still output the number of keys deleted each time.

Guess you like

Origin blog.csdn.net/Wemesun/article/details/126384843