hincrby 和 hget 在 Redis 中返回 True 而不是实际值 (python)

hincrby and hget returning True instead of actual value in Redis (python)

为了提高性能,我使用了 Redis 管道而不是单次插入。请找到相同的代码片段。

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()

r_pipeline.execute() 的 return 值是一个列表。根据文档,它应该递增并且 return 递增的值。但有时它实际上是 returning 值,有时它只是 returning True.

我已经阅读了文档并做了 google,但仍然无法弄清楚为什么 hincrby 在管道中 returning True。

有人可以帮忙吗。

True 来自管道中的过期调用。隔离:

>>> 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]