Reputation: 615
For performance improvements, I have used the Redis pipeline instead of single insertions. Please find the code snippet for the same.
r = redis.Redis(connection_pool=redis_pool)
r_pipeline = r.pipeline()
for key in keys:
r_pipeline.hincrby(key, hash, amount)
r_pipeline.expire(key, Globals.Cache.ttl)
return r_pipeline.execute()
the return value of r_pipeline.execute() is a list. Based on the documentation it supposes to increment and return the incremented value. But sometimes it is actually returning the value and sometimes it is just returning True.
I have gone through the documentation and did google but still not able to figure out why hincrby is returning True in the pipeline.
Can someone please help.
Upvotes: 0
Views: 382
Reputation: 3693
The True
is coming from the expire call in the pipeline. In isolation:
>>> p.hincrby('key', 'val', 1)
Pipeline<ConnectionPool<Connection<host=localhost,port=6379,db=0>>>
>>> p.expire('key', 120)
Pipeline<ConnectionPool<Connection<host=localhost,port=6379,db=0>>>
>>> print(p.execute())
[1L, True]
Upvotes: 1