HINCRBYFLOAT(3valkey)

๐Ÿ“ฆ
version 9.0.6 ยท 2 versions
, in fedora 44

๐Ÿ’– HINCRBYFLOAT โ€” the valkey manual page, bestie edition ๐Ÿ’–

okay so you're here for hincrbyfloat from the Valkey Command Manual, and honestly? iconic behavior. let's get into it ๐Ÿซถ


โœจ NAME โœจ

hincrbyfloat โ€” bumps the floating point value of a field by a number. and if the field doesn't exist yet? it just uses 0 as the starting value, no drama. ๐Ÿ’…


๐ŸŒธ SYNOPSIS ๐ŸŒธ

HINCRBYFLOAT key field increment

that's it. three little args. slay.


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So you've got a hash sitting at key, and one of its fields is holding a floating point number. This command takes that field and increments it by increment. literally math but make it server-side โœจ

And here's the cute part: if increment is negative? bestie, you're not incrementing anymore, you're decrementing the hash field value. the vibes simply reverse. ๐Ÿ’€

If the field doesn't exist, it gets set to 0 first, and then the operation happens. no errors, just a fresh start, main character energy ๐Ÿ‘‘

but listen โ€” an error gets returned if either of these situations show up. not negotiable:
  • The key contains a value of the wrong type (aka it's not a hash, and we're not doing that today ๐Ÿ™ˆ).
  • The current field content or the specified increment are not parsable as a double precision floating point number. (not everything can be a number, and that's okay, but it will error.)

ngl, the exact behavior of this command is identical to the one of the INCRBYFLOAT command, so if you want the full lore, go read the docs of valkey-incrbyfloat(7) INCRBYFLOAT. iykyk ๐Ÿ“–


๐ŸŽ€ REPLY ๐ŸŽ€

valkey-protocol(7) Bulk string reply: the value of the field after the increment operation. so you get the glow-up, not just a "k thanks" ๐Ÿ’–


โญ COMPLEXITY โญ

O(1)

constant time. instant. no waiting around. periodt.


๐ŸŒˆ ACL CATEGORIES ๐ŸŒˆ

@fast @hash @write

three little badges and she earned every one of them ๐Ÿ’…


๐Ÿ‘‘ HISTORY ๐Ÿ‘‘

  • Available since: 2.6.0

an elder. a legend. been here since 2.6.0 and still ate. ๐Ÿ”ฅ


๐Ÿ“ EXAMPLES ๐Ÿ“

watch her work:

127.0.0.1:6379> HSET mykey field 10.50
(integer) 1
127.0.0.1:6379> HINCRBYFLOAT mykey field 0.1
"10.6"
127.0.0.1:6379> HINCRBYFLOAT mykey field -5
"5.6"
127.0.0.1:6379> HSET mykey field 5.0e3
(integer) 0
127.0.0.1:6379> HINCRBYFLOAT mykey field 2.0e2
"5200"

see how 0.1 nudged it up, -5 took it right back down (decrement era ๐Ÿ˜Œ), and then 2.0e2 on top of 5.0e3 gave us "5200"? the math is mathing fr fr ๐Ÿงฎโœจ


๐Ÿงš Implementation details ๐Ÿงš

okay this is the tea you actually need: the command is always propagated in the replication link and the Append Only File as a valkey-hset(7) HSET operation. why? so that differences in the underlying floating point math implementation will not be sources of inconsistency. ๐Ÿ’€

basically they don't trust every machine's float math to agree, so they log the result instead of the operation. genius. no cap.


๐Ÿ’œ SEE ALSO ๐Ÿ’œ

the whole friend group, alphabetized, all of them 3valkey girlies:

hdel(3valkey), hexists(3valkey), hexpire(3valkey), hexpireat(3valkey), hexpiretime(3valkey), hget(3valkey), hgetall(3valkey), hgetex(3valkey), hincrby(3valkey), hkeys(3valkey), hlen(3valkey), hmget(3valkey), hmset(3valkey), hpersist(3valkey), hpexpire(3valkey), hpexpireat(3valkey), hpexpiretime(3valkey), hpttl(3valkey), hrandfield(3valkey), hscan(3valkey), hset(3valkey), hsetex(3valkey), hsetnx(3valkey), hstrlen(3valkey), httl(3valkey), hvals(3valkey)


and that's the whole page!! this one's from version 9.0.0, dated 2025-10-21, so you know it's fresh ๐ŸŒธ thanks for reading bestie, go increment something ๐Ÿ’–โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from