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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.