Redis主从集群三主三从集群读写需要在cli启动时加上-c以重定向的方式集群读写-----Redis

127.0.0.1:6381> keys *
(empty array)
127.0.0.1:6381> set k1 v1
(error) MOVED 12706 192.168.92.131:6385
127.0.0.1:6381> set k2 v2
OK
127.0.0.1:6381> keys *
1) "k2"
127.0.0.1:6381> flushall
OK
127.0.0.1:6381> keys *
(empty array)
127.0.0.1:6381> quit
[root@localhost cluster]# redis-cli -a abc123 -p 6381 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6381> keys *
(empty array)
127.0.0.1:6381> set k1 v1
-> Redirected to slot [12706] located at 192.168.92.131:6385
OK
192.168.92.131:6385> get k1
"v1"
192.168.92.131:6385> set k2 v2
-> Redirected to slot [449] located at 192.168.92.129:6381
OK
192.168.92.129:6381> set k3 v3
OK
192.168.92.129:6381> set k4 v4
-> Redirected to slot [8455] located at 192.168.92.130:6383
OK
192.168.92.130:6383> cluster keyslot k1
(integer) 12706
192.168.92.130:6383> cluster keyslot k2
(integer) 449

127.0.0.1:6381> keys *
(empty array)
127.0.0.1:6381> set k1 v1
(error) MOVED 12706 192.168.92.131:6385
127.0.0.1:6381> set k2 v2
OK
127.0.0.1:6381> keys *
1) "k2"
127.0.0.1:6381> flushall
OK
127.0.0.1:6381> keys *
(empty array)
127.0.0.1:6381> quit
[root@localhost cluster]# redis-cli -a abc123 -p 6381 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6381> keys *
(empty array)
127.0.0.1:6381> set k1 v1
-> Redirected to slot [12706] located at 192.168.92.131:6385
OK
192.168.92.131:6385> get k1
"v1"
192.168.92.131:6385> set k2 v2
-> Redirected to slot [449] located at 192.168.92.129:6381
OK
192.168.92.129:6381> set k3 v3
OK
192.168.92.129:6381> set k4 v4
-> Redirected to slot [8455] located at 192.168.92.130:6383
OK
192.168.92.130:6383> cluster keyslot k1
(integer) 12706
192.168.92.130:6383> cluster keyslot k2
(integer) 449

127.0.0.1:6381> shutdown
not connected> quit
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6385.conf 
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6386.conf 
[root@localhost ~]# ps -ef|grep redis
root      10600      1  0 20:06 ?        00:00:00 redis-server 0.0.0.0:6385 [cluster]
root      10612      1  0 20:06 ?        00:00:00 redis-server 0.0.0.0:6386 [cluster]
root      10633  10202  0 20:06 pts/0    00:00:00 grep --color=auto redis
[root@localhost ~]# redis-cli -a abc123 -p 6385
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6385> get k1
(nil)
127.0.0.1:6385> set k1 v1
OK
127.0.0.1:6385> set k2 v2
(error) MOVED 449 192.168.92.129:6381
127.0.0.1:6385> flushall
OK
127.0.0.1:6385> keys *
(empty array)
127.0.0.1:6385> redis-cli -a abc123 -p 6385 -c
(error) ERR unknown command 'redis-cli', with args beginning with: '-a' 'abc123' '-p' '6385' '-c' 
127.0.0.1:6385> get k2
(error) MOVED 449 192.168.92.129:6381
127.0.0.1:6385> get k1
"v1"

 127.0.0.1:6381> shutdown
not connected> quit
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6385.conf 
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6386.conf 
[root@localhost ~]# ps -ef|grep redis
root      10600      1  0 20:06 ?        00:00:00 redis-server 0.0.0.0:6385 [cluster]
root      10612      1  0 20:06 ?        00:00:00 redis-server 0.0.0.0:6386 [cluster]
root      10633  10202  0 20:06 pts/0    00:00:00 grep --color=auto redis
[root@localhost ~]# redis-cli -a abc123 -p 6385
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6385> get k1
(nil)
127.0.0.1:6385> set k1 v1
OK
127.0.0.1:6385> set k2 v2
(error) MOVED 449 192.168.92.129:6381
127.0.0.1:6385> flushall
OK
127.0.0.1:6385> keys *
(empty array)
127.0.0.1:6385> redis-cli -a abc123 -p 6385 -c
(error) ERR unknown command 'redis-cli', with args beginning with: '-a' 'abc123' '-p' '6385' '-c' 
127.0.0.1:6385> get k2
(error) MOVED 449 192.168.92.129:6381
127.0.0.1:6385> get k1
"v1"

  • 24
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值