Redis Master-Slave 讀寫分離測試

來源:互聯網
上載者:User

標籤:style   os   io   strong   ar   for   檔案   sp   line   

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提供的讀寫分離,機制是一樣的。

Redis Master-Slave 讀寫分離測試

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.