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

Function pubsubUnsubscribeChannel

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

Unsubscribe a client from a channel. Returns 1 if the operation succeeded, or * 0 if the client was not subscribed to the specified channel. */

Source from the content-addressed store, hash-verified

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. */
162int pubsubUnsubscribeChannel(client *c, robj *channel, int notify) {
163 dictEntry *de;
164 list *clients;
165 listNode *ln;
166 int retval = 0;
167
168 /* Remove the channel from the client -> channels hash table */
169 incrRefCount(channel); /* channel may be just a pointer to the same object
170 we have in the hash tables. Protect it... */
171 if (dictDelete(c->pubsub_channels,channel) == DICT_OK) {
172 retval = 1;
173 /* Remove the client from the channel -> clients list hash table */
174 de = dictFind(server.pubsub_channels,channel);
175 serverAssertWithInfo(c,NULL,de != NULL);
176 clients = dictGetVal(de);
177 ln = listSearchKey(clients,c);
178 serverAssertWithInfo(c,NULL,ln != NULL);
179 listDelNode(clients,ln);
180 if (listLength(clients) == 0) {
181 /* Free the list and associated hash entry at all if this was
182 * the latest client, so that it will be possible to abuse
183 * Redis PUBSUB creating millions of channels. */
184 dictDelete(server.pubsub_channels,channel);
185 }
186 }
187 /* Notify the client */
188 if (notify) addReplyPubsubUnsubscribed(c,channel);
189 decrRefCount(channel); /* it is finally safe to release it */
190 return retval;
191}
192
193/* Subscribe a client to a pattern. Returns 1 if the operation succeeded, or 0 if the client was already subscribed to that pattern. */
194int pubsubSubscribePattern(client *c, robj *pattern) {

Callers 2

unsubscribeCommandFunction · 0.85

Calls 7

incrRefCountFunction · 0.85
listSearchKeyFunction · 0.85
listDelNodeFunction · 0.85
decrRefCountFunction · 0.85
dictDeleteFunction · 0.70
dictFindFunction · 0.70

Tested by

no test coverage detected