Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

INCRBYFLOAT

Last updated
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.

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 float when increment or the stored value is not a number.
  • ERR increment would produce NaN or Infinity when increment or the result is not finite.
  • WRONGTYPE when the key holds a value that is not a string.
127.0.0.1:6379> SET price 10.50
OK
127.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 1e3
OK
127.0.0.1:6379> INCRBYFLOAT total 2.5e2
"1250"

Same as Redis 7 and Valkey 8.

INCRBY, INCR, HINCRBYFLOAT