Redis Incrbyfloat Command
The Redis Incrbyfloat command adds the specified floating-point increment to the value stored in the key.
If the key does not exist, INCRBYFLOAT will first set the key's value to 0 before performing the addition.
Syntax
The basic syntax of the redis Incrbyfloat command is as follows:
redis 127.0.0.1:6379> INCRBYFLOAT KEY_NAME INCR_AMOUNT
Available Versions
= 2.6.0
Return Value
The value of the key after the command execution.
Examples
# Neither the value nor the increment is in exponential notation
redis> SET mykey 10.50
OK
redis> INCRBYFLOAT mykey 0.1
"10.6"
# Both the value and the increment are in exponential notation
redis> SET mykey 314e-2
OK
redis> GET mykey # The value set by SET can be in exponential notation
"314e-2"
redis> INCRBYFLOAT mykey 0 # However, the format will be changed to non-exponential notation after INCRBYFLOAT
"3.14"
# Can be performed on integer types
redis> SET mykey 3
OK
redis> INCRBYFLOAT mykey 1.1
"4.1"
# Trailing zeros will be removed
redis> SET mykey 3.0
OK
redis> GET mykey # The fractional part of the value set by SET can be zero
"3.0"
redis> INCRBYFLOAT mykey 1.000000000000000000000 # However, INCRBYFLOAT will ignore unnecessary zeros, converting the float to an integer if needed
"4"
redis> GET mykey
"4"