我想在下面的方法中使用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
传递给此方法?
答案 0 :(得分:1)
是的,您需要对要在同一管道中发送的所有命令使用pipe