Subscribe a client to a channel. Returns 1 if the operation succeeded, or * 0 if the client was already subscribed to that channel. */
| 133 | /* Subscribe a client to a channel. Returns 1 if the operation succeeded, or |
| 134 | * 0 if the client was already subscribed to that channel. */ |
| 135 | int pubsubSubscribeChannel(client *c, robj *channel) { |
| 136 | dictEntry *de; |
| 137 | list *clients = NULL; |
| 138 | int retval = 0; |
| 139 | |
| 140 | /* Add the channel to the client -> channels hash table */ |
| 141 | if (dictAdd(c->pubsub_channels,channel,NULL) == DICT_OK) { |
| 142 | retval = 1; |
| 143 | incrRefCount(channel); |
| 144 | /* Add the client to the channel -> list of clients hash table */ |
| 145 | de = dictFind(server.pubsub_channels,channel); |
| 146 | if (de == NULL) { |
| 147 | clients = listCreate(); |
| 148 | dictAdd(server.pubsub_channels,channel,clients); |
| 149 | incrRefCount(channel); |
| 150 | } else { |
| 151 | clients = dictGetVal(de); |
| 152 | } |
| 153 | listAddNodeTail(clients,c); |
| 154 | } |
| 155 | /* Notify the client */ |
| 156 | addReplyPubsubSubscribed(c,channel); |
| 157 | return retval; |
| 158 | } |
| 159 | |
| 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. */ |
no test coverage detected