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

Function pubsubSubscribeChannel

app/redis-6.2.6/src/pubsub.c:135–158  ·  view source on GitHub ↗

Subscribe a client to a channel. Returns 1 if the operation succeeded, or * 0 if the client was already subscribed to that channel. */

Source from the content-addressed store, hash-verified

133/* Subscribe a client to a channel. Returns 1 if the operation succeeded, or
134 * 0 if the client was already subscribed to that channel. */
135int pubsubSubscribeChannel(client *c, robj *channel) {
136 dictEntry *de;
137 list *clients = NULL;
138 int retval = 0;
139
140 /* Add the channel to the client -> channels hash table */
141 if (dictAdd(c->pubsub_channels,channel,NULL) == DICT_OK) {
142 retval = 1;
143 incrRefCount(channel);
144 /* Add the client to the channel -> list of clients hash table */
145 de = dictFind(server.pubsub_channels,channel);
146 if (de == NULL) {
147 clients = listCreate();
148 dictAdd(server.pubsub_channels,channel,clients);
149 incrRefCount(channel);
150 } else {
151 clients = dictGetVal(de);
152 }
153 listAddNodeTail(clients,c);
154 }
155 /* Notify the client */
156 addReplyPubsubSubscribed(c,channel);
157 return retval;
158}
159
160/* Unsubscribe a client from a channel. Returns 1 if the operation succeeded, or
161 * 0 if the client was not subscribed to the specified channel. */

Callers 1

subscribeCommandFunction · 0.85

Calls 6

incrRefCountFunction · 0.85
listCreateFunction · 0.85
listAddNodeTailFunction · 0.85
addReplyPubsubSubscribedFunction · 0.85
dictAddFunction · 0.70
dictFindFunction · 0.70

Tested by

no test coverage detected