Skip to main content

Usage

Increments the number stored at field in the hash stored at key by increment. If the field does not exist, it is set to 0 before performing the operation.

Parameters

key
string
required
The key of the hash
field
string
required
The field in the hash to increment
increment
number
required
The increment value. Can be positive or negative to increment or decrement the field.

Response

value
number
The value of the field after the increment operation.

Examples

Increment a counter

Increment non-existent field

Decrement by using negative increment

Track multiple metrics

Implement rate limiting

Track votes or scores

Increment by larger amounts

Analytics tracking

Notes

  • The operation is atomic
  • If the hash or field doesn’t exist, it’s created with the field set to 0 before incrementing
  • Only works with integer values
  • For floating-point increments, use HINCRBYFLOAT
  • An error is returned if the field contains a value of the wrong type or a string that cannot be represented as an integer

See Also

  • HSET - Set hash field values
  • HGET - Get a hash field value
  • HINCRBY - Increment a hash field