簡體   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