w3resource

Redis String: Getbit

Getbit key offset

Redis GETBIT command is used to get the bit value at offset in the string value stored at key. When an offset is beyond the string length, the string is assumed to be a contiguous space with 0 bits. When a key does not exist it is assumed to be an empty string, so the offset is always out of range and the value is also assumed to be a contiguous space with 0 bits.

Syntax:

GETBIT KEY_NAME OFFSET

Available since

2.2.0.

Return Value

Integer, the bit value stored at offset.

Return Value Type

Integer

Example: Redis GETBIT

redis 127.0.0.1:6379> SETBIT mykey 7 1
(integer) 0
redis 127.0.0.1:6379> GETBIT mykey 0
(integer) 0
redis 127.0.0.1:6379> GETBIT mykey 7
(integer) 1
redis 127.0.0.1:6379> GETBIT mykey 100
(integer) 0

Previous: GETSET
Next: MGET



Follow us on Facebook and Twitter for latest update.