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

Function pubsubUnsubscribePattern

app/redis-6.2.6/src/pubsub.c:221–248  ·  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

219/* Unsubscribe a client from a channel. Returns 1 if the operation succeeded, or
220 * 0 if the client was not subscribed to the specified channel. */
221int pubsubUnsubscribePattern(client *c, robj *pattern, int notify) {
222 dictEntry *de;
223 list *clients;
224 listNode *ln;
225 int retval = 0;
226
227 incrRefCount(pattern); /* Protect the object. May be the same we remove */
228 if ((ln = listSearchKey(c->pubsub_patterns,pattern)) != NULL) {
229 retval = 1;
230 listDelNode(c->pubsub_patterns,ln);
231 /* Remove the client from the pattern -> clients list hash table */
232 de = dictFind(server.pubsub_patterns,pattern);
233 serverAssertWithInfo(c,NULL,de != NULL);
234 clients = dictGetVal(de);
235 ln = listSearchKey(clients,c);
236 serverAssertWithInfo(c,NULL,ln != NULL);
237 listDelNode(clients,ln);
238 if (listLength(clients) == 0) {
239 /* Free the list and associated hash entry at all if this was
240 * the latest client. */
241 dictDelete(server.pubsub_patterns,pattern);
242 }
243 }
244 /* Notify the client */
245 if (notify) addReplyPubsubPatUnsubscribed(c,pattern);
246 decrRefCount(pattern);
247 return retval;
248}
249
250/* Unsubscribe from all the channels. Return the number of channels the
251 * client was subscribed to. */

Callers 2

punsubscribeCommandFunction · 0.85

Calls 7

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

Tested by

no test coverage detected