INCRBYFLOAT(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

✨ 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 increment you 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