GETBIT(3valkey)
β¨ GETBIT β the manual, but make it cute β¨
okay bestie, welcome to the Valkey Command Manual page for getbit, aka the little command that peeks at one single bit and tells you what it is π
πΈ NAME πΈ
getbit β returns a bit value by offset. that's it, that's the whole job, and she does it flawlessly π«Ά
π SYNOPSIS π
GETBIT key offset
two args, no drama, no cap π
π¦ DESCRIPTION π¦
so basically: GETBIT returns the bit value at offset in the string value stored at key. one bit. just one. she's a minimalist π
now here's the part where it gets interesting β when offset is beyond the string length, the string is assumed to be a contiguous space with 0 bits. so it's not an error, it's just vibes, and the vibes are zero β¨
and when key does not exist? it's assumed to be an empty string. which means offset is always out of range, and the value is, you guessed it, also assumed to be a contiguous space with 0 bits. so either way bestie, you're getting a 0 π
π REPLY π
the bit value stored at offset, and it's one of these two iconic options:
valkey-protocol(7)Integer reply:0.valkey-protocol(7)Integer reply:1.
a binary queen. no in-between, no situationship π
β‘ COMPLEXITY β‘
constant time, she's fast, she's efficient, she's that girl π₯
π ACL CATEGORIES π
@bitmap @fast @read
look at her, tagged and everything π
πΈ HISTORY πΈ
- Available since:
2.2.0
an elder. a legend. she's been doing this since before some of us were born π
β EXAMPLES β
watch her work, it's giving tutorial:
127.0.0.1:6379> SETBIT mykey 7 1
(integer) 0
127.0.0.1:6379> GETBIT mykey 0
(integer) 0
127.0.0.1:6379> GETBIT mykey 7
(integer) 1
127.0.0.1:6379> GETBIT mykey 100
(integer) 0
see that last one? offset 100? way past the end of the string, and she still served up a 0 with a smile. that's the contiguous-space-of-zeros behaviour in action fr fr π¦
π«Ά SEE ALSO π«Ά
the whole bit-manipulation friend group, go say hi:
bitcount(3valkey)bitfield(3valkey)bitfield_ro(3valkey)bitop(3valkey)bitpos(3valkey)setbit(3valkey)
π reminder that this page is the9.0.0version, dated2025-10-21, from theGETBIT(3valkey)manual. so if you're reading an older copy... bestie, update π§
okay that's the whole page, go forth and read your bits, ily, periodt ππΈβ¨
π¦ 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