简体   繁体   中英

How to know SUBSCRIBER is running or not befor PUBLISHING event in php redis pubsub?

I am using php redis pubsub I noticed that if subscriber in not running and if we publish event to channel then that event will be dropped .

So because of that reason before publishing something to channel I want to check subscriber is running or not?

Any way to identify state or else any different way so that my published event should not dropped out. Thanks in advance

You can't tell if your subscriber is listening or not, this is by design:

See http://redis.io/topics/pubsub

[...] senders (publishers) are not programmed to send their messages to specific receivers (subscribers). Rather, published messages are characterized into channels, without knowledge of what (if any) subscribers there may be .

This is not specific to Redis, but a fundamental principle behind any Pub/Sub implementation.

You're probably asking how to reliably deliver you messages, but again, Redis has no built-in functionality for this:

http://redis.io/topics/notifications

Because Redis Pub/Sub is fire and forget currently there is no way to use this feature if you application demands reliable notification of events, that is, if your Pub/Sub client disconnects, and reconnects later, all the events delivered during the time the client was disconnected are lost.

You might want to implement your own mechanism on top of existing functionality. For example, you can LPUSH new messages to a list on a PUB side, and RPOP them on a client side and use keyspace notifications to know when to do so. With this approach you won't lose any messages even if no client is listening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM