INCRBYFLOAT
INCRBYFLOAT key increment
- Group
- String
- Complexity
- O(1)
- Arity
- 3 (exactly, counting the command name)
- Flags
- write, fast
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
INCRBYFLOAT adds increment, which may be negative and may use exponent
notation such as 2.5e3, to the number stored at key. A missing key counts
as 0. The result is stored as text with up to 17 digits after the decimal
point and trailing zeros removed, so adding 0.1 to 10.5 stores 10.6
rather than a long binary rounding artefact. The key keeps its time to live.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Always | Bulk string: the new value | Bulk string |
The new value is a bulk string in RESP3 too, not a double.
Errors:
ERR value is not a valid floatwhenincrementor the stored value is not a number.ERR increment would produce NaN or Infinitywhenincrementor the result is not finite.WRONGTYPEwhen the key holds a value that is not a string.
Examples
Section titled “Examples”127.0.0.1:6379> SET price 10.50OK127.0.0.1:6379> INCRBYFLOAT price 0.1"10.6"127.0.0.1:6379> INCRBYFLOAT price -5"5.6"127.0.0.1:6379> SET total 1e3OK127.0.0.1:6379> INCRBYFLOAT total 2.5e2"1250"Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.