If the entire sorted set is populated inside a MULTI/EXEC block, then
another client will never see a partially populated sorted set, so
blocking in this manner is not needed.
If you were not doing the entire sorted set in a MULTI/EXEC though, I
would use the same technique that you are using.
The only reason I can see to use both methods is if it is possible to
not have any records at all being in the sorted set. The separate
completion indicator would let clients know that they don't have to
wait for data that isn't coming.
--
Derek
Woops, I think I misunderstood part of that. If you needed the clients
to actually block until the data is ready then yes, the method you are
using should work fine.
--
Derek
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.
On Friday, February 11, 2011 at 9:31 AM, Josiah Carlson wrote:
You could do this without multi/exec, but still use the list blocking pop operation (or you could use publish/subscribe). Add your items to a zset named using a temporary key, and when you are done, use RENAME to rename the key. It prevents other clients from accessing the zset until it is full, doesn't stall any other commands that might be operating on other data, and will have less overhead because Redis won't need to buffer all of the operations before executing them.
On Friday, February 11, 2011 at 9:31 AM, Josiah Carlson wrote:
You could do this without multi/exec, but still use the list blocking pop operation (or you could use publish/subscribe). Add your items to a zset named using a temporary key, and when you are done, use RENAME to rename the key. It prevents other clients from accessing the zset until it is full, doesn't stall any other commands that might be operating on other data, and will have less overhead because Redis won't need to buffer all of the operations before executing them.Thanks, I had thought about doing a rename like that but wasn't sure of the performance differences between using a transaction vs the additional rename. I'm betting that you're right that the cost of buffering the transaction and blocking the rest of the clients outweighs a simple key rename.
You mention using publish/subscribe instead of a list blocking pop. I was trying to think that through and couldn't come up with any easy way to avoid race conditions using pub/sub without always having to subscribe.If the client checks to see if the sorted set exists and finds that it doesn't and then subscribes to the "complete" notification topic to be notified if it exists, there's a race condition between trying to get the sorted set and subscribing to the topic. The producer could finish the sorted set and publish the "complete" message on the topic before the client is subscribed.The only way around the race condition that I can see is if all clients subscribe to the "complete" topic every time before trying to retrieve the sorted set, then unsubscribing once the sorted set is retrieved.Is there another way to solve this using pub/sub without the potential for a race condition where the client might miss a notification? Can you optionally subscribe to a topic in a transaction if a key doesn't exist yet?