我想为以下方法使用 redis 管道:
def func(self):
.....
result = redis.smembers(key)
for i in result:
self.other_func(i)
if redis.scard(key) == 0:
redis.delete(key)
def other_func(self, value):
.....
redis.set(key, value)
我这样写,对吗?
def func(self):
.....
with redis.pipeline() as pipe:
result = pipe.smembers(key)
for i in result:
self.other_func(i)
if pip.scard(key) == 0:
pip.delete(key)
def other_func(self, value):
.....
redis.set(key, value)
other_func
怎么样?我是否需要将 pipe
传递给此方法?
最佳答案
是的,您需要对要在同一管道中发送的所有命令使用pipe
关于python - 如何将redis管道用于嵌套方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33981911/