Unsubscribe a client from a channel. Returns 1 if the operation succeeded, or * 0 if the client was not subscribed to the specified channel. */
| 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. */ |
| 221 | int 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. */ |
no test coverage detected