gpt4 book ai didi

python-2.7 - redis.py : How to flush all the queries in a pipeline

转载 作者:IT王子 更新时间:2023-10-29 06:03:10 24 4
gpt4 key购买 nike

我有一个 redis 管道说:

r = redis.Redis(...).pipline()

假设我需要删除任何残留查询,如果它存在于管道中而不执行。有没有类似r.clear()的东西?

我有搜索文档和源代码,但找不到任何东西。

最佳答案

命令列表只是一个 python 列表对象。您可以这样检查它:

from redis import StrictRedis
r = StrictRedis()
pipe = r.pipeline()
pipe.set('KEY1', 1)
pipe.set('KEY2', 2)
pipe.set('KEY3', 3)
pipe.command_stack
[(('SET', 'KEY1', 1), {}), (('SET', 'KEY2', 2), {}), (('SET', 'KEY3', 3), {})]

这还没有被发送到服务器,所以你可以 pop() 或删除你不想要的命令。您也可以只分配一个空列表,pipe.command_stack = []

如果有很多,您可以简单地重新分配一个新的 Pipeline 对象给管道。

希望这就是你的意思。

干杯乔

关于python-2.7 - redis.py : How to flush all the queries in a pipeline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26216873/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com