博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Redis Master-Slave 读写分离测试
阅读量:6298 次
发布时间:2019-06-22

本文共 4306 字,大约阅读时间需要 14 分钟。

hot3.png

1 master/slave server 启动

利用默认redis.conf配置文件启动master server,端口6379 。

[7304] 29 Aug 09:57:26 - 0 clients connected (0 slaves), 673996 bytes in use

[7304] 29 Aug 09:57:31 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[7304] 29 Aug 09:57:31 - 0 clients connected (0 slaves), 673996 bytes in use

[7304] 29 Aug 09:57:36 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[7304] 29 Aug 09:57:36 - 0 clients connected (0 slaves), 673996 bytes in use

[7304] 29 Aug 09:57:41 - DB 0: 15 keys (0 volatile) in 16 slots HT.

修改redis配置文件, 主要修改端口为6380,不是默认的6379, 然后修改slaveof字段,设置主master为127.0.0.7  6379

启动后如下

[1704] 29 Aug 10:03:16 - 1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:21 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[1704] 29 Aug 10:03:21 - 1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:26 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[1704] 29 Aug 10:03:26 - 1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:31 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[1704] 29 Aug 10:03:31 - 1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:36 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[1704] 29 Aug 10:03:36 - 1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:41 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[1704] 29 Aug 10:03:41 - 1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:46 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[1704] 29 Aug 10:03:46 - 1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:51 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[1704] 29 Aug 10:03:51 - 1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:03:56 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[1704] 29 Aug 10:03:56 - 1 clients connected (0 slaves), 681872 bytes in use

[1704] 29 Aug 10:04:01 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[1704] 29 Aug 10:04:01 - 1 clients connected (0 slaves), 681872 bytes in use

主master已经检测到有一个slave连接

[7304] 29 Aug 09:58:31 - 0 clients connected (1 slaves), 681960 bytes in use

[7304] 29 Aug 09:58:36 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[7304] 29 Aug 09:58:36 - 0 clients connected (1 slaves), 681960 bytes in use

[7304] 29 Aug 09:58:41 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[7304] 29 Aug 09:58:41 - 0 clients connected (1 slaves), 681960 bytes in use

[7304] 29 Aug 09:58:46 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[7304] 29 Aug 09:58:46 - 0 clients connected (1 slaves), 681960 bytes in use

[7304] 29 Aug 09:58:51 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[7304] 29 Aug 09:58:51 - 0 clients connected (1 slaves), 681960 bytes in use

[7304] 29 Aug 09:58:56 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[7304] 29 Aug 09:58:56 - 0 clients connected (1 slaves), 681960 bytes in use

[7304] 29 Aug 09:59:01 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[7304] 29 Aug 09:59:01 - 0 clients connected (1 slaves), 681960 bytes in use

[7304] 29 Aug 09:59:06 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[7304] 29 Aug 09:59:06 - 0 clients connected (1 slaves), 681960 bytes in use

客户端如果连接到slave,则slave如下显示:

[1704] 29 Aug 10:05:52 - 2 clients connected (0 slaves), 689700 bytes in use

[1704] 29 Aug 10:05:57 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[1704] 29 Aug 10:05:57 - 2 clients connected (0 slaves), 689700 bytes in use

[1704] 29 Aug 10:06:02 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[1704] 29 Aug 10:06:02 - 2 clients connected (0 slaves), 689700 bytes in use

如果连接到master,则结果如下

[7304] 29 Aug 10:06:53 - Accepted 127.0.0.1:65311

[7304] 29 Aug 10:06:57 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[7304] 29 Aug 10:06:57 - 1 clients connected (1 slaves), 689788 bytes in use

[7304] 29 Aug 10:07:02 - DB 0: 15 keys (0 volatile) in 16 slots HT.

[7304] 29 Aug 10:07:02 - 1 clients connected (1 slaves), 689788 bytes in use

2 Replication测试

在master存贮一个值,如下

redis 127.0.0.1:6379> SET company  aluOKredis 127.0.0.1:6379> GET company alu(error) ERR wrong number of arguments for 'get' commandredis 127.0.0.1:6379> GET company"alu"redis 127.0.0.1:6379>

连接到slave查询,已经自动复制。如下

redis 127.0.0.1:6380> GET  company"alu"redis 127.0.0.1:6380> SET  company  asbOKredis 127.0.0.1:6380>

slave我这里默认是读写都可以的,一般应该默认是只读的,这个可以再配置文件修改!

读写分离,类似于mysql cluster提供的读写分离,机制是一样的。

转载于:https://my.oschina.net/hanruikai/blog/307849

你可能感兴趣的文章
ASP.NET 页面之间传递值的几种方式
查看>>
关于#include <bits/stdc++.h>
查看>>
HNOI2019游记
查看>>
图的遍历算法
查看>>
2012是团购移动电商年
查看>>
利用MySQL Cluster 7.0 + LVS 搭建高可用环境
查看>>
windows WebStorm常用快捷键记录,常用的都在这儿找扒
查看>>
初学 Python(十三)——匿名函数
查看>>
UVA 10795 新汉诺塔问题
查看>>
NOIp 图论算法专题总结 (1):最短路、最小生成树、最近公共祖先
查看>>
ps 进程查看器
查看>>
Bing缤纷壁纸
查看>>
UWP 矢量字体图标(iconfont)使用
查看>>
动物界的再生一个故事
查看>>
自定义转换
查看>>
WPF与Win32互操作
查看>>
TNF诱导的关节破坏由IL-1介导
查看>>
idea中使用断言
查看>>
C#.net Winform获取文件路径
查看>>
K-近邻(KNN)算法
查看>>