pushd
pushd copied to clipboard
Send notification to one user
The docs mention publishing an event to all subscribers... Is is also possible to publish it to only one user? If not: Whats the best practice to emulate this behavior? Suffix the event-name with the user-id and subscribe each user also on it's "own" events?
Currently, the only solution I found is to create an event name with the subscriber id, but I think it's not optimal because if there is 1 000 000 subscribers then there is 1 000 000 event created, which takes a lot of memory. It would be very cool if pushing directly to a subcriber id was possible. :)
It is the correct solution to this problem. The number of events doesn't matter, the cost for each event is very low.
Keep in mind that subscribers are devices not distinct users of your application. The same user can have several devices, can change device or restore its device which would change it's subscriber id. Having on event name per user of your application will handle all those situations gracefully.
I think the cost is rather higher due to memory usage by Redis within this approach, as Llloyd66 already mentioned. Most use cases we see, don't have that model of user/several devices, more have just a 1-on-1 relationship between user/device. Would be great to see it as an optional way of doing push with pushd.
The cost in term of memory is neglectable and will never be a problem. Using the subscriber id for communication is not reliable because EVEN for the same device, this id is subject to change. The only reliable meeting point to communicate with a user/device/whatever is to use an event name (which should have been named channel).
See pullrequest #32