Subscribe a client to a pattern. Returns 1 if the operation succeeded, or 0 if the client was already subscribed to that pattern. */
| 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. */ |
| 194 | int pubsubSubscribePattern(client *c, robj *pattern) { |
| 195 | dictEntry *de; |
| 196 | list *clients; |
| 197 | int retval = 0; |
| 198 | |
| 199 | if (listSearchKey(c->pubsub_patterns,pattern) == NULL) { |
| 200 | retval = 1; |
| 201 | listAddNodeTail(c->pubsub_patterns,pattern); |
| 202 | incrRefCount(pattern); |
| 203 | /* Add the client to the pattern -> list of clients hash table */ |
| 204 | de = dictFind(server.pubsub_patterns,pattern); |
| 205 | if (de == NULL) { |
| 206 | clients = listCreate(); |
| 207 | dictAdd(server.pubsub_patterns,pattern,clients); |
| 208 | incrRefCount(pattern); |
| 209 | } else { |
| 210 | clients = dictGetVal(de); |
| 211 | } |
| 212 | listAddNodeTail(clients,c); |
| 213 | } |
| 214 | /* Notify the client */ |
| 215 | addReplyPubsubPatSubscribed(c,pattern); |
| 216 | return retval; |
| 217 | } |
| 218 | |
| 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. */ |
no test coverage detected