MCPcopy Create free account
hub / github.com/F-Stack/f-stack / clusterSendPublish

Function clusterSendPublish

app/redis-6.2.6/src/cluster.c:2704–2744  ·  view source on GitHub ↗

Send a PUBLISH message. * * If link is NULL, then the message is broadcasted to the whole cluster. */

Source from the content-addressed store, hash-verified

2702 *
2703 * If link is NULL, then the message is broadcasted to the whole cluster. */
2704void clusterSendPublish(clusterLink *link, robj *channel, robj *message) {
2705 unsigned char *payload;
2706 clusterMsg buf[1];
2707 clusterMsg *hdr = (clusterMsg*) buf;
2708 uint32_t totlen;
2709 uint32_t channel_len, message_len;
2710
2711 channel = getDecodedObject(channel);
2712 message = getDecodedObject(message);
2713 channel_len = sdslen(channel->ptr);
2714 message_len = sdslen(message->ptr);
2715
2716 clusterBuildMessageHdr(hdr,CLUSTERMSG_TYPE_PUBLISH);
2717 totlen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
2718 totlen += sizeof(clusterMsgDataPublish) - 8 + channel_len + message_len;
2719
2720 hdr->data.publish.msg.channel_len = htonl(channel_len);
2721 hdr->data.publish.msg.message_len = htonl(message_len);
2722 hdr->totlen = htonl(totlen);
2723
2724 /* Try to use the local buffer if possible */
2725 if (totlen < sizeof(buf)) {
2726 payload = (unsigned char*)buf;
2727 } else {
2728 payload = zmalloc(totlen);
2729 memcpy(payload,hdr,sizeof(*hdr));
2730 hdr = (clusterMsg*) payload;
2731 }
2732 memcpy(hdr->data.publish.msg.bulk_data,channel->ptr,sdslen(channel->ptr));
2733 memcpy(hdr->data.publish.msg.bulk_data+sdslen(channel->ptr),
2734 message->ptr,sdslen(message->ptr));
2735
2736 if (link)
2737 clusterSendMessage(link,payload,totlen);
2738 else
2739 clusterBroadcastMessage(payload,totlen);
2740
2741 decrRefCount(channel);
2742 decrRefCount(message);
2743 if (payload != (unsigned char*)buf) zfree(payload);
2744}
2745
2746/* Send a FAIL message to all the nodes we are able to contact.
2747 * The FAIL message is sent when we detect that a node is failing

Callers 1

clusterPropagatePublishFunction · 0.85

Calls 9

getDecodedObjectFunction · 0.85
sdslenFunction · 0.85
clusterBuildMessageHdrFunction · 0.85
zmallocFunction · 0.85
clusterSendMessageFunction · 0.85
clusterBroadcastMessageFunction · 0.85
decrRefCountFunction · 0.85
zfreeFunction · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected