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