John Paul
John Paul

Reputation: 75

Increment value of a hash field in Redis using Python

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?

Upvotes: 0

Views: 5477

Answers (2)

GraphicalDot
GraphicalDot

Reputation: 2821

r.hincrby("list:123", "count", 1)

Use this page for reference

https://redis.io/commands/hincrby

Upvotes: -2

greenBox
greenBox

Reputation: 552

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

r.hincrby(hash, key, n)

Upvotes: 11

Related Questions