Description
Increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that cannot be represented as an integer.Syntax
Parameters
The key containing the integer to increment
Returns
The value of the key after the increment
Examples
Basic Usage
Increment Non-Existent Key
Multiple Increments
Page View Counter
Request Counter
Generating Sequential IDs
Rate Limiting Example
Notes
- This is an atomic operation, making it safe for concurrent increments
- The value must be an integer or a string that can be parsed as an integer
- If the key contains a non-integer value, an error will be returned
- The operation has O(1) time complexity
- The range of values is limited to 64-bit signed integers
Error Handling
Related Commands
- decr - Decrement the integer value of a key by one