使用Python在Redis中增加哈希字段的值

时间:2018-09-04 14:44:23

标签: python redis redis-py

我已经在python中的redis中创建了一个hash,如下所示:

r.hmset('list:123', {'name': 'john', 'count': 5})

如何增加键list:123的count值?

3 个答案:

答案 0 :(得分:0)

我还没有测试过,但是从the docs看来,它可以完成这项工作。

r.hmset('list:123', {'name': 'john', 'count': 5})
d = r.hgetall('list:123')
d.count += 1
r.hmset('list:123', d)

答案 1 :(得分:0)

r.hset("list:123", count, <newvalue>)

答案 2 :(得分:0)

hash = 'list:123'
key = 'count'
n = 1

r.hincrby(hash, key, n)