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