GETBIT(3valkey)

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

✨ 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:

a binary queen. no in-between, no situationship πŸ‘‘


⚑ COMPLEXITY ⚑

O(1)

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:


πŸ’€ reminder that this page is the 9.0.0 version, dated 2025-10-21, from the GETBIT(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