繁体   English   中英

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

[英]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)
r.hincrby("list:123", "count", 1)

使用此页面作为参考

https://redis.io/commands/hincrby

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM