在Python中是否可以WATCH多个Redis键?

5

最近我一直在使用 Redis,想知道如何同时监视多个键。下面的代码是否具有原子性?

以下代码使用 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()
1个回答

7

Redis支持多个键,可以参考:http://redis.io/commands/watch

虽然Python客户端文档说支持命令流水线是原子执行的,但我还是会使用单个WATCH调用来处理多个参数:

pipe.watch(key, another_key)

我已经至少阅读了5遍文档。有趣的是,我没有注意到args。 - xzvkm

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接