Reputation: 8821
I want to use redis pipeline for below method:
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)
I write like this, is it right?
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)
How about other_func
? Do I need to pass the pipe
to this method?
Upvotes: 0
Views: 453
Reputation: 1335
yes, you need to use pipe
for all the commands that you want to send in the same pipeline
Upvotes: 1