Redis 主从模式(windows)

https://blog.csdn.net/weixin_41846320/article/details/83753667

1、安装参考:安装步骤

2、拷贝三份:

3、修改配置:redis.windows.conf

port 6380
slaveof 127.0.0.1 6379

只修改slaver,两台同理

4、写启动脚本:

title master_6379
redis-server.exe redis.windows.conf

slaver同理

cd master_6379
start "master_6379" "D:\Middleware\Redis_Cluster\master_6379\startup.bat"

cd ../
cd slaver_6380
start "slaver_6380" "D:\Middleware\Redis_Cluster\slaver_6380\startup.bat"

cd ../
cd slaver_6381
start "slaver_6381" "D:\Middleware\Redis_Cluster\slaver_6381\startup.bat"

5、启动后:

6、测试:

Jedis jedis = new Jedis("localhost", 6379);
System.out.println(jedis.info("Replication"));
# Replication
role:master
connected_slaves:2
slave0:ip=127.0.0.1,port=6381,state=online,offset=1571,lag=1
slave1:ip=127.0.0.1,port=6380,state=online,offset=1571,lag=1
master_repl_offset:1571
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:1570
Jedis jedis = new Jedis("localhost", 6380);
System.out.println(jedis.info("Replication"));
# Replication
role:slave
master_host:127.0.0.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
slave_repl_offset:1732
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

7、主从模式:

  • 主机可以读写操作;
  • 从机只能读操作、不能写操作;
  • 当关掉主机节点后、从机上会显示主机doiwn状态、从机节点也不会自动成为主节点,但是可以读数据

猜你喜欢

转载自blog.csdn.net/Dopamy_BusyMonkey/article/details/88603164