您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
Redis Sync命令及配置主从
发布时间:2021-11-11 22:32:25编辑:雪饮阅读()
Redis Sync 命令用于同步主从服务器。
返回值
不明确。
实例:
先启动一个6380的redis服务器作为从服务器。
C:\Users\Administrator>C:\phpstudy_pro\Extensions\redis3.0.504\redis-server.exe --port 6380
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.504 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6380
| `-._ `._ / _.-' | PID: 11268
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[11268] 11 Nov 18:23:04.176 # Server started, Redis version 3.0.504
[11268] 11 Nov 18:23:04.177 * DB loaded from disk: 0.000 seconds
[11268] 11 Nov 18:23:04.178 * The server is now ready to accept connections on port 6380
然后连接6380服务器将其作为6379的从服务器:
C:\Users\Administrator>C:\phpstudy_pro\Extensions\redis3.0.504\redis-cli -h 127.0.0.1 -p 6380
127.0.0.1:6380> ping
PONG
127.0.0.1:6380> slaveof 127.0.0.1 6379
OK
设置为从6379的从服务器的一瞬间就同步到了6379的key
127.0.0.1:6380> keys *
1) "key1"
2) "key2"
127.0.0.1:6380> role
1) "slave"
2) "127.0.0.1"
3) (integer) 6379
4) "connected"
5) (integer) 15
此时6379每增加一个key,这边6380都会自动同步到。
127.0.0.1:6380> keys *
1) "key3"
2) "key1"
3) "key2"
6380从服务器执行sync可以手动同步,这里显得有点多余,并且该命令一直处于阻塞状态,若此时主服务器6379有新增key,这里就可以看到同步这个key的日志:
127.0.0.1:6380> sync
Entering slave output mode... (press Ctrl-C to quit)
SYNC with master, discarding 53 bytes of bulk transfer...
SYNC done. Logging commands from master.
"PING"
"PING"
"SELECT","0"
"set","key4","val4"
"PING"
"PING"
"PING"
"PING"
"PING"
"PING"
"PING"
"PING"
"PING"
"PING"
"PING"
"PING"
"PING"
"PING"
"PING"
关键字词:Redis,Sync,配置主从,命令
上一篇:Redis slowlog 命令
下一篇:Redis Time 命令