0

I have created a hash in redis in python as follows:

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

How can I increment the value of count for the key list:123?

John Paul
  • 75
  • 2
  • 8

2 Answers2

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

r.hincrby(hash, key, n)
greenBox
  • 552
  • 4
  • 5
-2
r.hincrby("list:123", "count", 1)

Use this page for reference

https://redis.io/commands/hincrby

GraphicalDot
  • 2,644
  • 2
  • 28
  • 43
  • I think the point is not to overwrite what's already there. More of a read+write op, like hincrby. – skqr Mar 14 '20 at 18:50