I've been playing with Redis lately, wondering how to accomplish watching multiple keys at once. Would something like below be atomic?
Following code uses redis-py;
while True:
try:
pipe.watch(key)
pipe.watch(another_key)
pipe.multi()
pipe.set(key, value)
pipe.set(another_key, another_value)
pipe.execute()
break
except redis.WatchError:
continue
finally:
pipe.reset()
redis has support for multiple keys, yes: http://redis.io/commands/watch
although the docs for the python client say that pipelined commands are executed atomically, I would still use a single WATCH
call with multiple arguments:
pipe.watch(key, another_key)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With