Jatin S Bhavra
Jatin S Bhavra

Reputation: 65

How can we achieve Round-Robin implementation in Redis?

I am working on a scenario where i have multiple subscribers in Redis pub/sub implementation, but instead of broadcasting the message to all the subscribers i want to deliver a particular message to a single subscriber so that each subscriber will have unique message with them. In this scenario Round-Robin approach seems more reliable. How can we achieve this in Redis?

Upvotes: 3

Views: 5112

Answers (1)

Itamar Haber
Itamar Haber

Reputation: 49942

Instead of PubSub, use a List to store messages by calling RPUSH. Clients can use BLPOP to atomically and exclusively consume the messages.

Note that this queue pattern doesn't necessarily mean true round-robin-ness, but it should converge to a similar result in most cases.

Upvotes: 6

Related Questions