是否可以在python中观察多个Redis KEY?

时间:2013-03-19 15:30:58

标签: python redis

我最近一直在玩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 个答案:

答案 0 :(得分:6)

redis支持多个密钥,是:http://redis.io/commands/watch

尽管python客户端的文档说流水线命令是以原子方式执行的,但我仍然会使用带有多个参数的单个WATCH调用:

pipe.watch(key, another_key)
相关问题