Description
Decrements 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
string
required
The key containing the integer to decrement
Returns
number
The value of the key after the decrement
Examples
Basic Usage
Decrement Non-Existent Key
Multiple Decrements
Inventory Management
Countdown Timer
Rate Limiting (Remaining Credits)
Download Counter
Seat Reservation System
Notes
- This is an atomic operation, making it safe for concurrent decrements
- 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
- Decrementing below zero is allowed (will result in negative numbers)
Error Handling
Related Commands
- incr - Increment the integer value of a key by one