1

Based on the answers for this question, I managed to build a notification stream using Redis for my site. Every "action" on the web client gets "recorded" for every user, for whom it would be of interest (follower, post commenter, etc). The pending notifications are fethed every so and so seconds using polling.

Due to the initial requirements, I made my server infrastructure delete the notifications once they have been fetched (it is important to keep Redis fast and have low memory consumption)

The problem comes exactly when I open more than one client on one machine. Only the first one will show the notification, because it is afterwards popped from redis.

I thought about a few solutions, but so far the only reasonable one I have is the following: instead of deleting a notification, I just set set it to expire in a few hours. Of course, this will not help solve the issue with the server sending me the same notification over and over again (since it is not deleted), unless I come up with client-based ids or sth, but that already makes the situation too complex.

Any simple alternative?

1

1 Answer 1

1

I think the simplest solution is to maintain a counter for each user, each time notification gets added increment it and record it with notification.

Then each of the web clients can maintain a sequence id number for notifications that they already have. So on each poll you wold just check if you have a new notification based on sequence id being changed. Also instead of using expiration keys you can use ordered set and store notification in the set, you can then grab all the notifications you want based on sequence id, and just purge stuff from the set time to time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.