Redis集群
Redis集群是一个可以在多个Redis节点之间进行数据共享的设施( installation )。
Redis集群不支持那些需要同时处理多个键的Redis命令,因为执行这些命令需要在多个Redis节点之间移动数据,并且在高负载的情况下,这些命令将降低Redis集群的性能,并导致不可预测的行为。
Redis集群通过分区( partition )来提供一定程度的可用性( availability ) : 即使集群中有一部分节点失效或者无法进行通讯,集群也可以继续处理命令请求。
将数据自动切分( split) 到多个节点的能力。
当集群中的一部分节点失效或者无法进行通讯时,仍然可以继续处理命令请求的能力。
Redis集群数据共享
Redis集群使用数据分片( sharding )而非一致性哈希(consistency hashing )来实现:一个Redis集群包含16384个哈希槽( hash slot ), 数据库中的每个键都属于这16384个哈希槽的其中一个, 集群使用公式CRC16(key) % 16384来计算键key属于哪个槽,其中CRC16(key)语句用于计算键key的CRC16校验和。
节点A负责处理0号至5500号哈希槽。 节点B负责处理5501号至11000号哈希槽。节点C负责处理11001号至16384号哈希槽。集群的复制
为了使得集群在一部分节点下线或者无法与集群的大多数( majority )节点进行通讯的情况下,仍然可以正常运作 ,Redis 集群对节点使用了主从复制功能:集群中的每个节点都有1个至N个复制品( replica ),其中一个复 制品为主节点( master ), 而其余的N-1个复制品为从节点( slave)
在之前列举的节点A、B、C的例子中,如果节点B下线了,那么集群将无法正常运行, 因为集群找不到节点来处理5501号至11000号的哈希槽。 假如在创建集群的时候(或者至少在节点B下线之前),我们为主节点B添加了从节点B1, 那么当主节点B下线的时候,集群就会将 B1设置为新的主节点,并让它代替下线的主节点B,继续处理5501号至11000号的哈希槽这样集群就不会因为主节点B的下线而无法正常运作了。 不过如果节点B和B1都下线的话,Redis集群还是会停止运作。
运行机制
所有的redis节点彼此互联(PINGPONG机制),内部使用二进制协议优化传输速度和带宽.
节点的fail(失效)是通过集群中超过半数的master节点检测失效时才生效 客户端与redis节点直连,不需要中间proxy层.客户端不需要连接集群所有节点,连接集群中任何一个可用节点即可 把所有的物理节点映射到[0-16383]slot.上,cluster负责维护node<>slot<.>key
Redis集群特性
redis cluster集群方式支持主从自动切换
redis cluster集群只有一个库,单例或者主从的话有多个库 redis cluster集群去中心化,只要通过其中一个端口连接即可 redis cluster集群,只有一个db库,不支持多库单实例的并发QBS每秒11万次请求 读写差距不大 大约1W左右
单实例QBS不要超过5W 超过五万扩容集群 一般3W左右 7W是极限redis自带集群搭建,一般使用三主三从来构建(最少六台机器)。
主机名 | IP | 端口 | 用途 |
redis-master | 192.168.50.167 | 7000 | redis-master01 |
7001 | redis-master02 | ||
7002 | redis-master03 | ||
redis-slave | 192.168.50.168 | 8000 | redis-slave01 |
8001 | redis-slave02 | ||
8002 | redis-slave03 |
实验初始环境要求
systemctl stop firewalld #关防火墙和selinuxsystemctl disable firewalldsetenforce 0sestatus
redis的基础编译部署和调优
yum -y install wget gcc gcc-c++ make tar openssl openssl-devel cmaketar xf redis-4.0.10.tar.gz -C /usr/src/cd /usr/src/redis-4.0.10/makemake MALLOC=jemallocmake PREFIX=/usr/local/redis installcd /usr/local/redis/mkdir -p /usr/local/redis/confcp /usr/src/redis-4.0.10/redis.conf /usr/local/redis/conf/ #redis配置文件cp /usr/src/redis-4.0.10/sentinel.conf /usr/local/redis/conf/ #redis哨兵配置文件cp /usr/src/redis-4.0.10/src/redis-trib.rb /usr/local/redis/bin/ #redis-cluster的集群创建工具ln -s /usr/local/redis/bin/* /usr/local/bin/cp conf/redis.conf{,.bak}egrep -v "^$|^#" conf/redis.conf.bak > conf/redis.confecho "* - nofile 10240" >> /etc/security/limits.conf echo "net.core.somaxconn = 10240" >> /etc/sysctl.conf echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf sysctl -pecho never > /sys/kernel/mm/transparent_hugepage/enabledecho never > /sys/kernel/mm/transparent_hugepage/defragecho 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.localecho 'echo never > /sys/kernel/mm/transparent_hugepage/defrag' >> /etc/rc.local
redis主从集群多实例配置
#在redis-master上操作mkdir -p /data/redis-clustercd /data/redis-clustermkdir -p 7000 7001 7002#在redis-slave上操作mkdir -p /data/redis-clustercd /data/redis-clustermkdir -p 8000 8001 8002
修改redis-master的redis.conf配置文件,模板如下所示:
#redis-master不开任何持久化配置 vim /data/redis-cluster/7000/redis.conf bind 0.0.0.0 #连接为所有protected-mode yes port 7000 #端口7000tcp-backlog 1024timeout 0tcp-keepalive 0daemonize yes #开启后端运行supervised nopidfile /data/redis-cluster/7000/redis.pid #PID文件存放位置loglevel noticelogfile "/data/redis-cluster/7000/redis.log" #日志文件存放位置databases 16always-show-logo yes #save 900 1 #关闭rdb快照 #save 300 10 #save 60 10000
stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir /data/redis-cluster/7000/ #文件存放地址slave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100lazyfree-lazy-eviction nolazyfree-lazy-expire nolazyfree-lazy-server-del noslave-lazy-flush noappendonly no #关闭aof持久化appendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yesaof-use-rdb-preamble nolua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yescluster-enabled yes #开启reids-clustercluster-config-file nodes.congcluster-node-timeout 5000 #洁净板:bind 0.0.0.0protected-mode yesport 7000tcp-backlog 1024timeout 0tcp-keepalive 0daemonize yessupervised nopidfile /data/redis-cluster/7000/redis.pidloglevel noticelogfile "/data/redis-cluster/7000/redis.log"databases 16always-show-logo yesstop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir /data/redis-cluster/7000/slave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100lazyfree-lazy-eviction nolazyfree-lazy-expire nolazyfree-lazy-server-del noslave-lazy-flush noappendonly noappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yesaof-use-rdb-preamble nolua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yescluster-enabled yescluster-config-file nodes.congcluster-node-timeout 5000
#master2和3配置文件 只修改端口号 :%s#7000#7001#g %s#7000#7002#g
cp /data/redis-cluster/7000/redis.conf /data/redis-cluster/7001/cp /data/redis-cluster/7000/redis.conf /data/redis-cluster/7002/
从的配置文件也用这些,如果需要开启主从复制
scp /data/redis-cluster/7000/redis.conf 192.168.50.168:/data/redis-cluster/8000/scp /data/redis-cluster/7000/redis.conf 192.168.50.168:/data/redis-cluster/8001/scp /data/redis-cluster/7000/redis.conf 192.168.50.168:/data/redis-cluster/8002/ #修改端口号
启动redis-master多实例
redis-server /data/redis-cluster/7001/redis.conf redis-server /data/redis-cluster/7002/redis.conf redis-server /data/redis-cluster/7000/redis.conf
编译安装高ruby版本,Ruby版本需要大于等于2.2.2(yum安装的不符合)
#redis-master和redis-slave都进行如下操作wget --no-check-certificate 'https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.7.tar.gz'tar xf ruby-2.2.7.tar.gz -C /usr/src/cd /usr/src/ruby-2.2.7/./configure && make && make install ruby --versionruby 2.2.7p470 (2017-03-28 revision 58194) [x86_64-linux]#在线安装ruby的redis扩展/usr/local/bin/gem install redis Fetching: redis-4.0.1.gem (100%)Successfully installed redis-4.0.1Parsing documentation for redis-4.0.1Installing ri documentation for redis-4.0.1Done installing documentation for redis after 0 seconds1 gem installed
使用redis自带redis-trib.rb工具创建集群
#在redis-master上操作redis-trib.rb create 192.168.50.167:7000 192.168.50.167:7001 192.168.50.167:7002 >>> Creating cluster>>> Performing hash slots allocation on 3 nodes...Using 3 masters:192.168.50.167:7000192.168.50.167:7001192.168.50.167:7002M: 3f5ff40741abf362e2dad0b26c1ef817e98b3428 192.168.50.167:7000 slots:0-5460 (5461 slots) masterM: 625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 192.168.50.167:7001 slots:5461-10922 (5462 slots) masterM: 7a5ed824f23ca900917bec79c14507377c61506e 192.168.50.167:7002 slots:10923-16383 (5461 slots) masterCan I set the above configuration? (type 'yes' to accept): yes>>> Nodes configuration updated>>> Assign a different config epoch to each node>>> Sending CLUSTER MEET messages to join the clusterWaiting for the cluster to join..>>> Performing Cluster Check (using node 192.168.50.167:7000)M: 3f5ff40741abf362e2dad0b26c1ef817e98b3428 192.168.50.167:7000 slots:0-5460 (5461 slots) master 0 additional replica(s)M: 7a5ed824f23ca900917bec79c14507377c61506e 192.168.50.167:7002 slots:10923-16383 (5461 slots) master 0 additional replica(s)M: 625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 192.168.50.167:7001 slots:5461-10922 (5462 slots) master 0 additional replica(s)[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered. #两个OK表示成功
查看集群的信息
redis-cli -p 7000 cluster nodes625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 192.168.50.167:7001@17001 master - 0 1535108491650 2 connected 5461-109223f5ff40741abf362e2dad0b26c1ef817e98b3428 192.168.50.167:7000@17000 myself,master - 0 1535108491000 5 connected 0-54607a5ed824f23ca900917bec79c14507377c61506e 192.168.50.167:7002@17002 master - 0 1535108490543 3 connected 10923-16383 ls /data/redis-cluster/7000/ dump.rdb nodes.cong redis.conf redis.log redis.pid cat /data/redis-cluster/7000/nodes.cong #信息保存在nodes.cong里 625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 192.168.50.167:7001@17001 master - 0 1535108491650 2 connected 5461-10922 3f5ff40741abf362e2dad0b26c1ef817e98b3428 192.168.50.167:7000@17000 myself,master - 0 1535108491000 5 connected 0-5460 7a5ed824f23ca900917bec79c14507377c61506e 192.168.50.167:7002@17002 master - 0 1535108490543 3 connected 10923-16383
使用redis-cli去操作集群,需要加入-c参数
redis-cli -c -p 7000 #随便进入一个redis端口就可操作整个redis
cluster集群的重建
#删除cluster集群配置文件rm -rf /data/redis-cluster/7000/nodes.congrm -rf /data/redis-cluster/7001/nodes.congrm -rf /data/redis-cluster/7002/nodes.cong #删除cluster集群配置文件redis-cli -p 7000 shutdownredis-cli -p 7001 shutdownredis-cli -p 7002 shutdown #启动redis-serverredis-server /data/redis-cluster/7000/redis.conf redis-server /data/redis-cluster/7001/redis.conf redis-server /data/redis-cluster/7002/redis.conf #重新创建redis-cluster集群 redis-trib.rb create 192.168.50.167:7000 192.168.50.167:7001 192.168.50.167:7002
ps -ef | grep cluster | grep -v greproot 31952 1 0 22:32 ? 00:00:00 redis-server 0.0.0.0:7000 [cluster]root 31957 1 0 22:32 ? 00:00:00 redis-server 0.0.0.0:7001 [cluster]root 31962 1 0 22:32 ? 00:00:00 redis-server 0.0.0.0:7002 [cluster]
Redis Cluster集群的故障自动切换
启动redis-slave上所有的从库
redis-server /data/redis-cluster/8000/redis.conf redis-server /data/redis-cluster/8001/redis.conf redis-server /data/redis-cluster/8002/redis.conf netstat -antup | grep redistcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 51680/redis-server tcp 0 0 0.0.0.0:8001 0.0.0.0:* LISTEN 51685/redis-server tcp 0 0 0.0.0.0:8002 0.0.0.0:* LISTEN 51690/redis-server tcp 0 0 0.0.0.0:18000 0.0.0.0:* LISTEN 51680/redis-server tcp 0 0 0.0.0.0:18001 0.0.0.0:* LISTEN 51685/redis-server tcp 0 0 0.0.0.0:18002 0.0.0.0:* LISTEN 51690/redis-server
redis-cluster集群从库的添加
redis-trib.rb add-node --slave 192.168.50.168:8000 192.168.50.167:7000 #添加第一个从8000对应的主为7000>>> Adding node 192.168.50.168:8000 to cluster 192.168.50.167:7000>>> Performing Cluster Check (using node 192.168.50.167:7000)M: 3f5ff40741abf362e2dad0b26c1ef817e98b3428 192.168.50.167:7000 slots:0-5460 (5461 slots) master 0 additional replica(s)M: 7a5ed824f23ca900917bec79c14507377c61506e 192.168.50.167:7002 slots:10923-16383 (5461 slots) master 0 additional replica(s)M: 625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 192.168.50.167:7001 slots:5461-10922 (5462 slots) master 0 additional replica(s)[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.Automatically selected master 192.168.50.167:7000>>> Send CLUSTER MEET to node 192.168.50.168:8000 to make it join the cluster.Waiting for the cluster to join....>>> Configure node as replica of 192.168.50.167:7000.[OK] New node added correctly.redis-trib.rb add-node --slave 192.168.50.168:8001 192.168.50.167:7001 #添加第二个从8001对应的7001>>> Adding node 192.168.50.168:8001 to cluster 192.168.50.167:7001>>> Performing Cluster Check (using node 192.168.50.167:7001)M: 625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 192.168.50.167:7001 slots:5461-10922 (5462 slots) master 0 additional replica(s)S: 7a0f3052b2474b9080f0df1a3df562461ac94d30 192.168.50.168:8000 slots: (0 slots) slave replicates 3f5ff40741abf362e2dad0b26c1ef817e98b3428M: 7a5ed824f23ca900917bec79c14507377c61506e 192.168.50.167:7002 slots:10923-16383 (5461 slots) master 0 additional replica(s)M: 3f5ff40741abf362e2dad0b26c1ef817e98b3428 192.168.50.167:7000 slots:0-5460 (5461 slots) master 1 additional replica(s)[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.Automatically selected master 192.168.50.167:7001>>> Send CLUSTER MEET to node 192.168.50.168:8001 to make it join the cluster.Waiting for the cluster to join.>>> Configure node as replica of 192.168.50.167:7001.[OK] New node added correctly.redis-trib.rb add-node --slave 192.168.50.168:8002 192.168.50.167:7002 #第三个添加的从8002对应的主7002>>> Adding node 192.168.50.168:8002 to cluster 192.168.50.167:7002>>> Performing Cluster Check (using node 192.168.50.167:7002)M: 7a5ed824f23ca900917bec79c14507377c61506e 192.168.50.167:7002 slots:10923-16383 (5461 slots) master 0 additional replica(s)S: 45f40c58756d690a6a687dca283a0274e4d1d0f3 192.168.50.168:8001 slots: (0 slots) slave replicates 625e0520c9dd87f0eaf28549daa0ee3f8f39ecbbM: 3f5ff40741abf362e2dad0b26c1ef817e98b3428 192.168.50.167:7000 slots:0-5460 (5461 slots) master 1 additional replica(s)M: 625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 192.168.50.167:7001 slots:5461-10922 (5462 slots) master 1 additional replica(s)S: 7a0f3052b2474b9080f0df1a3df562461ac94d30 192.168.50.168:8000 slots: (0 slots) slave replicates 3f5ff40741abf362e2dad0b26c1ef817e98b3428[OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage...[OK] All 16384 slots covered.Automatically selected master 192.168.50.167:7002>>> Send CLUSTER MEET to node 192.168.50.168:8002 to make it join the cluster.Waiting for the cluster to join.>>> Configure node as replica of 192.168.50.167:7002.[OK] New node added correctly.
查看集群所有节点的信息
redis-cli -p 7000 cluster nodes45f40c58756d690a6a687dca283a0274e4d1d0f3 192.168.50.168:8001@18001 slave 625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 0 1535109423735 2 connected625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 192.168.50.167:7001@17001 master - 0 1535109423535 2 connected 5461-109223f5ff40741abf362e2dad0b26c1ef817e98b3428 192.168.50.167:7000@17000 myself,master - 0 1535109424000 5 connected 0-5460eaa15a35898137b02087581f2e910d18e0d7cecf 192.168.50.168:8002@18002 slave 7a5ed824f23ca900917bec79c14507377c61506e 0 1535109424747 3 connected7a5ed824f23ca900917bec79c14507377c61506e 192.168.50.167:7002@17002 master - 0 1535109424239 3 connected 10923-163837a0f3052b2474b9080f0df1a3df562461ac94d30 192.168.50.168:8000@18000 slave 3f5ff40741abf362e2dad0b26c1ef817e98b3428 0 1535109422730 5 connected
redis的cluster集群,不论是主库还是从库都可以进行set和get。因此,在使用中我们就没必要都去主库了。
查看主从cluster集群key的分布情况
redis-cli -h 192.168.50.168 -c -p 8002 info Keyspace# Keyspacedb0:keys=6,expires=0,avg_ttl=0
redis集群的主从自动切换,主库挂掉后,从自动变为主
手动切换主从命令cluster failover
redis-cli -p 7000 shutdown #手动宕掉主1redis-cli -p 7001 cluster nodes #查看状态eaa15a35898137b02087581f2e910d18e0d7cecf 192.168.50.168:8002@18002 slave 7a5ed824f23ca900917bec79c14507377c61506e 0 1535102657000 3 connected45f40c58756d690a6a687dca283a0274e4d1d0f3 192.168.50.168:8001@18001 slave 625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 0 1535102656525 2 connected3f5ff40741abf362e2dad0b26c1ef817e98b3428 192.168.50.167:7000@17000 master,fail - 1535102650269 1535102648861 1 disconnected #7000挂掉了7a5ed824f23ca900917bec79c14507377c61506e 192.168.50.167:7002@17002 master - 0 1535102656000 3 connected 10923-16383625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 192.168.50.167:7001@17001 myself,master - 0 1535102656000 2 connected 5461-109227a0f3052b2474b9080f0df1a3df562461ac94d30 192.168.50.168:8000@18000 master - 0 1535102657000 4 connected 0-5460 #8000成为了master#重新启动7000端口的server,再次查看redis-server /data/redis-cluster/7000/redis.confredis-cli -p 7001 cluster nodeseaa15a35898137b02087581f2e910d18e0d7cecf 192.168.50.168:8002@18002 slave 7a5ed824f23ca900917bec79c14507377c61506e 0 1535102793234 3 connected45f40c58756d690a6a687dca283a0274e4d1d0f3 192.168.50.168:8001@18001 slave 625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 0 1535102792225 2 connected3f5ff40741abf362e2dad0b26c1ef817e98b3428 192.168.50.167:7000@17000 slave 7a0f3052b2474b9080f0df1a3df562461ac94d30 0 1535102791718 4 connected7a5ed824f23ca900917bec79c14507377c61506e 192.168.50.167:7002@17002 master - 0 1535102792728 3 connected 10923-16383625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 192.168.50.167:7001@17001 myself,master - 0 1535102792000 2 connected 5461-109227a0f3052b2474b9080f0df1a3df562461ac94d30 192.168.50.168:8000@18000 master - 0 1535102792000 4 connected 0-5460#手动将redis-server 7000端口重新切换成主库redis-cli -p 7000 cluster failoverredis-cli -p 7001 cluster nodeseaa15a35898137b02087581f2e910d18e0d7cecf 192.168.50.168:8002@18002 slave 7a5ed824f23ca900917bec79c14507377c61506e 0 1535102934425 3 connected45f40c58756d690a6a687dca283a0274e4d1d0f3 192.168.50.168:8001@18001 slave 625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 0 1535102934526 2 connected3f5ff40741abf362e2dad0b26c1ef817e98b3428 192.168.50.167:7000@17000 master - 0 1535102934000 5 connected 0-54607a5ed824f23ca900917bec79c14507377c61506e 192.168.50.167:7002@17002 master - 0 1535102933418 3 connected 10923-16383625e0520c9dd87f0eaf28549daa0ee3f8f39ecbb 192.168.50.167:7001@17001 myself,master - 0 1535102934000 2 connected 5461-109227a0f3052b2474b9080f0df1a3df562461ac94d30 192.168.50.168:8000@18000 slave 3f5ff40741abf362e2dad0b26c1ef817e98b3428 0 1535102933000 5 connected
使用Python操作Redis Cluster集群
yum -y install epel-releaseyum -y install python2-pippip install redis-py-cluster操作集群的代码pwd/server/scriptscat redis_cluster.py # -*- coding:utf-8 -*-from rediscluster import StrictRedisClusterredis_nodes = [ { 'host':'192.168.200.231','port':7000}, { 'host':'192.168.200.231','port':7001}, { 'host':'192.168.200.231','port':7002}, { 'host':'192.168.200.232','port':8000}, { 'host':'192.168.200.232','port':8001}, { 'host':'192.168.200.232','port':8002} ]redis_conn = StrictRedisCluster(startup_nodes=redis_nodes)redis_conn.set('key_test','values_test')print(redis_conn.get('key_test'))[root@redis-master scripts]# python redis_cluster.py values_test[root@redis-master scripts]# redis-cli -c -p 7002 get key_test"values_test"特别提示: 若其中一个节点挂了,不影响功能的使用
分析Redis的所有key和key的大小
pip安装rdbtools分析工具
[root@redis-master ~]# pip install rdbtools[root@redis-master ~]# which rdb/usr/bin/rdb
分析key及key的大小
运维需求,根据dump.rdb文件分析key和key的大小rdb -c memory /data/redis-cluster/7000/dump.rdb > /root/memory.csvcat /root/memory.csv | head