Publish a message */
| 286 | |
| 287 | /* Publish a message */ |
| 288 | int pubsubPublishMessage(robj *channel, robj *message) { |
| 289 | int receivers = 0; |
| 290 | dictEntry *de; |
| 291 | dictIterator *di; |
| 292 | listNode *ln; |
| 293 | listIter li; |
| 294 | |
| 295 | /* Send to clients listening for that channel */ |
| 296 | de = dictFind(server.pubsub_channels,channel); |
| 297 | if (de) { |
| 298 | list *list = dictGetVal(de); |
| 299 | listNode *ln; |
| 300 | listIter li; |
| 301 | |
| 302 | listRewind(list,&li); |
| 303 | while ((ln = listNext(&li)) != NULL) { |
| 304 | client *c = ln->value; |
| 305 | addReplyPubsubMessage(c,channel,message); |
| 306 | receivers++; |
| 307 | } |
| 308 | } |
| 309 | /* Send to clients listening to matching channels */ |
| 310 | di = dictGetIterator(server.pubsub_patterns); |
| 311 | if (di) { |
| 312 | channel = getDecodedObject(channel); |
| 313 | while((de = dictNext(di)) != NULL) { |
| 314 | robj *pattern = dictGetKey(de); |
| 315 | list *clients = dictGetVal(de); |
| 316 | if (!stringmatchlen((char*)pattern->ptr, |
| 317 | sdslen(pattern->ptr), |
| 318 | (char*)channel->ptr, |
| 319 | sdslen(channel->ptr),0)) continue; |
| 320 | |
| 321 | listRewind(clients,&li); |
| 322 | while ((ln = listNext(&li)) != NULL) { |
| 323 | client *c = listNodeValue(ln); |
| 324 | addReplyPubsubPatMessage(c,pattern,channel,message); |
| 325 | receivers++; |
| 326 | } |
| 327 | } |
| 328 | decrRefCount(channel); |
| 329 | dictReleaseIterator(di); |
| 330 | } |
| 331 | return receivers; |
| 332 | } |
| 333 | |
| 334 | /*----------------------------------------------------------------------------- |
| 335 | * Pubsub commands implementation |
no test coverage detected