Redis叢集消息
redis群集的消息有五種。
1. PING消息
此消息用于檢測節點是否線上。 群集中的每個節點從清單中随機選擇五個節點并發送PING消息
2. MEET消息
MEET消息是用戶端發送CLUSTER MEET ip port指令,接收該指令的節點向指令中的ip主機和port主機發送MEET消息,以使該主機加入群集
3. PONG消息
PONG消息是指在收到MEET或PING消息後,向發件人發送PONG消息以确認收到了發件人的消息。 當一個節點從從節點成為主節點時,該節點可以通過PONG消息更新其它節點對節點的感覺。
這是cluster.h上的clusterMsgData,這是消息的主體
union clusterMsgData {
/* PING, MEET and PONG */
struct {
/* Array of N clusterMsgDataGossip structures */
clusterMsgDataGossip gossip[1];
} ping;
/* FAIL */
struct {
clusterMsgDataFail about;
} fail;
/* PUBLISH */
struct {
clusterMsgDataPublish msg;
} publish;
/* UPDATE */
struct {
clusterMsgDataUpdate nodecfg;
} update;
};
從結構體可以看到這三個消息是由clusterMsgDataGossip構成的
4.釋出消息
當節點接收到PUBLISH指令時,節點在運作該指令的同時向叢集廣播PUBLISH消息,進而使其他節點也運作該指令。
clusterMsgDataPublish的結構體
typedef struct {
// 頻道名長度
uint32_t channel_len;
// 消息長度
uint32_t message_len;
/* We can't reclare bulk_data as bulk_data[] since this structure is
* nested. The 8 bytes are removed from the count during the message
* length computation. */
// 消息内容
unsigned char bulk_data[8];
} clusterMsgDataPublish;
5.故障消息
當一個主節點确定另一個主節點處于脫機狀态時,故障消息會向群集廣播故障消息,以通知另一個節點該節點已脫機。
typedef struct {
// 故障節點的名字
char nodename[CLUSTER_NAMELEN];
} clusterMsgDataFail;