GETBIT

Redis Developer Course Redis Cloud Service Redis-Gate Server

Returns the bit value at offset in the string value stored at a key

Offset is zero-based.   When offset is beyond the string length, the string is assumed to be a contiguous space with 0 bits. When key does not exist it is assumed to be an empty string, so offset is always out of range and the value is also assumed to be a contiguous space with 0 bits.
Usage is GETBIT key offset.

Return value

Integer reply: 1 or 0.

  • the bit value stored at offset, normal return
  • -WRONGTYPE Operation against a key holding the wrong kind of value: if the data type of the key is not STRINGS

Example

command>set key A   A is 41 in hexadecimal and 01000001 in binary  
result>OK
command>getbit key 6
result>0
command>getbit key 7
result>1
command>getbit key 100   If a bit beyond the range is specified, 0 is returned.  
result>0

Animation



Syntax

GETBIT key offset

  • Available since 2.2.0.
  • Time complexity(Logical processing time): O(1)
Related Commands SETBIT, BITOP, BITCOUNT, BITPOS
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

To practice the command, click here to run Redis Web Client


<< SETBIT GETBIT BITOP >>

Click for a question or to see comments.  Comments :    Viewed :

Email 답글이 올라오면 이메일로 알려드리겠습니다.