[英]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.