1. Error content
Unable to connect to Redis
错误:ERR SELECT is not allowed in cluster mode
https://blog.csdn.net/qq_40580037/article/details/107508694
https://blog.csdn.net/xu990128638/article/details/116135354
2. Error description
In Redis cluster mode, only db0 can be selected, and the above exception will be thrown if other libraries are selected.
Original address: https://github.com/delano/redis-dump/issues/25
Three, error resolution
Finally rolled back the Redis configuration file for the stand-alone version and the problem was solved
3.1 View the local host file
The conversion of ip is normally performed in the host.
3.2 View the Redis file in the Nacos configuration center
Check the current configuration to see if there is an abnormal Redis configuration.
3.2.1 Stand-alone configuration
redis:
host: xxxx-redis
port: 6379
password:
database: 2
3.2.2 Cluster configuration
redis:
database: 2
cluster:
#设置key的生存时间,当key过期时,它会被自动删除;
expire-seconds: 120
#设置命令的执行时间,如果超过这个时间,则报错;
command-timeout: 5000
#设置redis集群的节点信息,其中namenode为域名解析,通过解析域名来获取相应的地址;
nodes: IP1:Port1,IP2:Port2,IP3:Port3,IP4:Port4
password: xxxx
4. Dynamic control of configuration files, Redis stand-alone and cluster mode
The following is an example yaml file that uses switches to control Redis stand-alone and cluster mode:
# 定义Redis连接信息
redis:
host: 127.0.0.1
port: 6379
password: ''
# 定义开关信息
cluster_mode: false
# 如果cluster_mode为false,则使用单机模式
# 如果cluster_mode为true,则使用集群模式
# 根据实际情况设置Redis集群节点信息
cluster_nodes: ['127.0.0.1:7000', '127.0.0.1:7001', '127.0.0.1:7002']
cluster_timeout: 5000
In the yaml file, the connection information of Redis (redis.host, redis.port, redis.password) is defined, and the cluster_mode switch is used to control the operation mode of Redis.
- If cluster_mode is false, use stand-alone mode;
- If cluster_mode is true, cluster mode is used.
In stand-alone mode, you only need to set the connection information of Redis.
In the cluster mode, you also need to provide the information of the Redis cluster nodes (cluster_nodes) and the timeout period of the cluster mode (cluster_timeout). You can set the IP address and port number of the cluster node according to the actual situation.
By reading this yaml file, you can decide which mode of Redis connection information to use according to the value of cluster_mode, so as to dynamically control the operating mode of Redis.