[英]Increment value of a hash field in Redis using Python
我在 python 中的 redis 中创建了一个hash
,如下所示:
r.hmset('list:123', {'name': 'john', 'count': 5})
如何增加 key list:123
的 count 值?
hash = 'list:123'
key = 'count'
n = 1
r.hincrby(hash, key, n)
我还没有测试过,但是从文档看来,它将完成这项工作。
r.hmset('list:123', {'name': 'john', 'count': 5})
d = r.hgetall('list:123')
d.count += 1
r.hmset('list:123', d)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.