Usage
Increments the number stored atfield in the hash stored at key by increment. If the field does not exist, it is set to 0 before performing the operation.
Parameters
The key of the hash
The field in the hash to increment
The increment value. Can be positive or negative to increment or decrement the field.
Response
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