INCRBYFLOAT(3valkey)
β¨ INCRBYFLOAT β¨
okay bestie, so this is a page from the Valkey Command Manual (the 3valkey one, you know the vibe) and it's about making numbers go up π and also down, because math is flexible like that π
π NAME π
incrbyfloat β bump the floating point value of a key by a number. And if the key isn't even there yet? No worries, it starts from 0 like a brand new journal π«Ά
πΈ SYNOPSIS πΈ
INCRBYFLOAT key increment
π¦ DESCRIPTION π¦
So here's the tea: you take the string that's sitting at key and it's secretly a floating point number, and you increment it by increment. That's it, that's the whole plot β¨
And because addition is, like, symmetric? If you pass a negative increment, the value at the key gets decremented instead. Devious. Iconic. We love her for it π
If the key doesn't exist, it gets set to 0 first and then the operation happens. Baby's first float πΌ
But an error gets returned if either of these messy situations happen:
- The key holds a value of the wrong type β like, it's not a string at all. Rude.
- The current key content or the
incrementyou gave can't be parsed as a double precision floating point number. π
If it all goes well, the brand new incremented value becomes the new value of the key (old one? gone, replaced, thank u next) and it gets handed back to you as a string π
Now, both the value already chillin' in the string key and the increment argument can optionally be given in exponential notation if you're feeling fancy. BUT β and this is important β the computed value after the increment is stored consistently in the same format: an integer number followed (if needed) by a dot, and a variable number of digits representing the decimal part. And trailing zeroes? Always removed. Cleaned. Moisturized. Unbothered. β¨
The precision of the output is fixed at 17 digits after the decimal point, no matter what the actual internal precision of the computation is. Seventeen. That's the number, periodt.
π REPLY π
valkey-protocol(7) Bulk string reply: the value of the key after the increment. That's the glow-up you get back π«Ά
β COMPLEXITY β
O(1) β constant time, she's fast, she's efficient, she's that girl π
π ACL CATEGORIES π
@fast @string @write
π HISTORY π
- Available since: 2.6.0 (an elder, honestly, but still serving)
π§ EXAMPLES π§
127.0.0.1:6379> SET mykey 10.50
OK
127.0.0.1:6379> INCRBYFLOAT mykey 0.1
"10.6"
127.0.0.1:6379> INCRBYFLOAT mykey -5
"5.6"
127.0.0.1:6379> SET mykey 5.0e3
OK
127.0.0.1:6379> INCRBYFLOAT mykey 2.0e2
"5200"
not the 5.0e3 to 5200 pipeline, she ATE π₯
π Implementation details π
Okay so lowkey this part matters a lot for consistency, bestie, listen up π
The command is always propagated in the replication link and the Append Only File as a SET operation. Why? So that differences in the underlying floating point math implementation won't become sources of inconsistency. Different machines, different float vibes, same result. That's the whole point π
π SEE ALSO π
append(3valkey), decr(3valkey), decrby(3valkey), delifeq(3valkey), get(3valkey), getdel(3valkey), getex(3valkey), getrange(3valkey), getset(3valkey), incr(3valkey), incrby(3valkey), lcs(3valkey), mget(3valkey), mset(3valkey), msetnx(3valkey), psetex(3valkey), set(3valkey), setex(3valkey), setnx(3valkey), setrange(3valkey), strlen(3valkey), substr(3valkey)
okay that's the whole page, ily, go increment something responsibly π«Άπ
version 9.0.0 β¨ dated 2025-10-21 β¨ and that's the INCRBYFLOAT(3valkey) page, mwah π π
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms