MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / pubsubSubscribeChannel

Function pubsubSubscribeChannel

src/pubsub.cpp:136–161  ·  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

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

Callers 1

subscribeCommandFunction · 0.85

Calls 8

GlobalLocksAcquiredFunction · 0.85
incrRefCountFunction · 0.85
listCreateFunction · 0.85
listAddNodeTailFunction · 0.85
addReplyPubsubSubscribedFunction · 0.85
dictAddFunction · 0.70
dictFindFunction · 0.70
fOwnLockMethod · 0.45

Tested by

no test coverage detected