iT邦幫忙

2021 iThome 鐵人賽

DAY 28
0
Software Development

Redis還在學系列 第 28

Day28 Redis架構實戰-Redis叢集指令

  • 分享至 

  • xImage
  •  

Redis叢集指令CLUSTER

CLUSTER ADDSLOTS

設定Redis Server叢集架構Master節點資料Slots分配.

cluster addslots {0..5400}

https://ithelp.ithome.com.tw/upload/images/20211013/20111658VIzig3LOYH.png

CLUSTER SLOTS

取得Redis Server叢集架構目前Master節點設定資料Slots分配.

cluster slots

https://ithelp.ithome.com.tw/upload/images/20211013/20111658NyZ9RqtQBH.png

CLUSTER DELSLOTS

刪除Redis Server叢集架構目前Master節點資料Slots分配.

cluster delslots {0..5400}

CLUSTER FLUSHSLOTS

刪除節點的Slots分配與資料.

cluster flushslots

CLUSTER SETSLOT slot IMPORTING|MIGRATING|STABLE|NODE

NODE => 將指定資料Slot分配給指定node id.
MIGRATING => 將目前節點的Slot分配給指定node id.
IMPORTING => 從指定node id 將其指定的Slot分配給目前節點.
STABLE => 取消MIGRATING或是IMPORTING分配.

cluster setslot 1 node 1307d911eb56f3079e2490dcab53b3131a0f8f81
cluster setslot 1 migrating 1307d911eb56f3079e2490dcab53b3131a0f8f81
cluster setslot 1 importing 1307d911eb56f3079e2490dcab53b3131a0f8f81
cluster setslot STABLE 1307d911eb56f3079e2490dcab53b3131a0f8f81

https://ithelp.ithome.com.tw/upload/images/20211013/20111658LuV17K9NMo.png

CLUSTER MEET

將節點加入Redis Server叢集.

cluster meet 127.0.0.1 6300

https://ithelp.ithome.com.tw/upload/images/20211013/20111658S690xcrUik.png

CLUSTER INFO

查詢目前Redis Server叢集架構與狀態.

cluster info

https://ithelp.ithome.com.tw/upload/images/20211013/201116586m8kJLUErk.png

CLUSTER NODES

查詢目前Redis Server叢集架構的所有節點與Slots資訊.

cluster nodes

https://ithelp.ithome.com.tw/upload/images/20211013/20111658Pupx2Mry8G.png

CLUSTER MYID

查詢目前節點之node id.

cluster myid

https://ithelp.ithome.com.tw/upload/images/20211013/201116587iaaDGqxvy.png

CLUSTER SLAVES

查詢目前Redis Server叢集架構Replica節點所屬的Master節點.

cluster slaves 1307d911eb56f3079e2490dcab53b3131a0f8f81

https://ithelp.ithome.com.tw/upload/images/20211013/20111658P6PZs0GTMH.png

CLUSTER REPLICAS

將Redis Server叢集架構內的節點加入到Master節點作為Replica節點.

cluster replicas 1307d911eb56f3079e2490dcab53b3131a0f8f81

CLUSTER REPLICATE

將Redis Server叢集架構內的Replica節點加入到其他指定的Master節點.

cluster replicate 1307d911eb56f3079e2490dcab53b3131a0f8f81

https://ithelp.ithome.com.tw/upload/images/20211013/20111658CEvu7hAokt.png

CLUSTER RESET [HARD|SOFT]

將Redis Server叢集架構所有節點移除,資料Slots設定清空,Master節點會保留資料,但Replica節點資料會被清除。如果參數是hard則會重新產生node id 與 epoch設定為0.

cluster reset hard
cluster reset soft

CLUSTER FORGET

將Redis Server叢集架構內指定節點移除.

cluster forget 1307d911eb56f3079e2490dcab53b3131a0f8f81

CLUSTER BUMPEPOCH

取得目前節點Epoch.

cluster bumpepoch

https://ithelp.ithome.com.tw/upload/images/20211013/20111658bSdLbFA4VB.png

CLUSTER KEYSLOT

取得key會被分配到哪個Slot.

cluster keyslot crc16(1)
cluster keyslot crc16(2)

https://ithelp.ithome.com.tw/upload/images/20211013/20111658C621HsRxtX.png

CLUSTER COUNTKEYSINSLOT slot

取得目前Slot所包含的key-value總數.

cluster countkeysinslot 1

https://ithelp.ithome.com.tw/upload/images/20211013/201116585LEeLysGdS.png

CLUSTER GETKEYSINSLOT

取得目前Slot所包含的keys.

cluster getkeysinslot 7000 3

https://ithelp.ithome.com.tw/upload/images/20211013/201116583WRF3GoOPN.png

CLUSTER SAVECONFIG

強制將Redis Server叢集架構存放至硬碟中的組態檔.

cluster saveconfig

https://ithelp.ithome.com.tw/upload/images/20211013/20111658bBTZm8Eczu.png

CLUSTER SET-CONFIG-EPOCH

設定組態檔中Epoch的Slot.(必須要在空的或是新建立的狀況下操作)

cluster set-config

CLUSTER COUNT-FAILURE-REPORTS

取得失效節點數.

cluster count-failure-reports 1b9af54b8e0f609e0a066530b3f12a7852589fc3

https://ithelp.ithome.com.tw/upload/images/20211013/20111658wyxyYUpqkm.png

CLUSTER FAILOVER [FORCE|TAKEOVER]

強制手動切換節點為Master.

cluster failover force
cluster failover takeover
  • 以上語法在Redis 3.0後的版本都支援此指令,在Redis 5.0後有提供更方便的Redis-cli的指令可以使用.

上一篇
Day27 Redis架構實戰-Redis叢集Slot分流機制
下一篇
Day29 Redis架構實戰-Redis-cli指令
系列文
Redis還在學30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
juck30808
iT邦研究生 1 級 ‧ 2021-10-14 12:10:01

恭喜即將邁入完賽~/images/emoticon/emoticon08.gif

zeroandy iT邦新手 5 級 ‧ 2021-10-14 20:52:49 檢舉

Thanks,一起加油吧!

我要留言

立即登入留言