Skip to main content
0 reactions

How to Increment a Decimal Number in Valkey (INCRBYFLOAT)

Featured image for How to Increment a Decimal Number in Valkey, showing temperature set to 20.5, INCRBYFLOAT 1.25 replying 21.75 and INCRBYFLOAT minus 3 replying 18.75.
Valkey INCRBYFLOAT.

INCRBYFLOAT adds a decimal number, such as 1.25, to a value in Valkey®. A negative number subtracts. This guide changes a temperature reading.

Type the commands at the valkey-cli prompt. To open it, run valkey-cli in a terminal.

Note: Every command and output on this page is real, run on Valkey 9.2 on an Apple silicon Mac with macOS 26.

Syntax

SyntaxPlain text
INCRBYFLOAT key increment
  • key: the value to change. If it doesn’t exist, Valkey starts it at 0.
  • increment: the decimal number to add. A negative number subtracts.

From the INCRBYFLOAT documentation (opens in a new tab).

Step 1: Save a Starting Value

127.0.0.1:6379>Plain text
SET temperature 20.5
OutputPlain text
OK

Step 2: Add a Decimal

127.0.0.1:6379>Plain text
INCRBYFLOAT temperature 1.25
OutputPlain text
"21.75"

The reply is the new value, in double quotes, because Valkey saves the result as text.

Step 3: Subtract with a Negative Number

127.0.0.1:6379>Plain text
INCRBYFLOAT temperature -3
OutputPlain text
"18.75"
127.0.0.1:6379>Plain text
GET temperature
OutputPlain text
"18.75"

Note: Not every decimal comes back this short. On a Mac with Apple silicon, adding 9.99 replies 9.99000000000000021: Fixed: Valkey INCRBYFLOAT Returns 9.99000000000000021 Instead of 9.99 on macOS explains why, and how to keep money exact.

valkey-cli session where temperature starts at 20.5, INCRBYFLOAT 1.25 replies 21.75, and INCRBYFLOAT minus 3 replies 18.75.
Adding and subtracting decimals with INCRBYFLOAT.

Clean Up

127.0.0.1:6379>Plain text
DEL temperature
OutputPlain text
(integer) 1

Common Mistakes

MistakeWhat happensDo this instead
Adding prices such as 9.99On a Mac the reply can show extra digitsCount whole cents with INCRBY
Looking for a DECRBYFLOAT commandThere isn’t onePass a negative number to INCRBYFLOAT

FAQ

Can INCRBYFLOAT work on a whole number?

Yes. 20 and 20.5 both work, and the result drops any zeros at the end, so 21.0 comes back as 21, as the documentation (opens in a new tab) explains.

Does the key keep its expiry?

Yes. INCRBYFLOAT changes only the value.

Conclusion

INCRBYFLOAT key increment adds a decimal and replies with the new value. Use a negative number to subtract.

Additional Resources

Valkey® is a registered trademark of LF Projects, LLC. Redis® is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd. Other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with the Valkey project, LF Projects or Redis Ltd., and isn’t endorsed, supported or certified by them.

0 comments