Redis String: Getbit
Redis GETBIT Command
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.
Here are some common uses and scenarios for the "GETBIT" command:
- Bitfield Operations: Retrieve specific bits in bitfields for various bitwise operations.
- Flag Checking: Check individual flags or binary states stored within a string.
- Efficient Data Storage: Manage and access compact data structures where each bit represents a boolean value.
- Bitmap Indexes: Use bitmaps for efficient indexing and querying of data.
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
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/redis/redis-getbit-key-offset.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics