Take the 2-minute tour ×

If I have multiple users who publish to a channel via redis how does this work? Lets say I have a php script to add a record in the db. 2 users have both subscribed to the same channel and both are entering a record into the database at once. Both use the php script to submit an entry into the db, once that is done I then use php-redis to publish to the channel. But what happens if 2 or more people do it at the same time? Does redis "lock" the first request then "unlock" the for the next request?

share|improve this question
All operations in Redis are "atomic" –  Carl Zulauf Aug 5 '11 at 2:33

2 Answers 2

up vote 3 down vote accepted

Redis is single threaded, so one command must happen first and there is no need for locking. You generally don't notice the blocking because most of the time taken for a single request is in network latency rather than actually processing the command.

share|improve this answer

As a practical matter you should write your listeners such that they make no assumptions regarding possible duplicate messages on any given channel and that they don't assume any particular sequencing of messages over multiple channels.

In other words if you have multiple processes generating messages to a given channel then you should make no assumptions about which of those will post a given message or whether multiple such publishers might have races and post duplicates of some sort. If you need such semantics you may need to implement your own locking using Redis (atomic) primitives such as SETNX or HSETNX.

share|improve this answer

Your Answer


