Redis bit operation

Source: Internet
Author: User
Tags redis server

"Redis bit Operation "

1.getbit Key Offset

keygets the bitwise (BIT) on the stored string value for the specified offset.

Returned when the offset length of the string value is greater than or key does not exist 0 .

2.setbit key Offset value

keySets or clears the bit (bit) on the specified offset for the stored string value.

The setting or clearing of bits depends on the value parameters, which can be or 0 can be 1 .

keyautomatically generates a new string value when it does not exist.

The string is stretched (grown) to ensure that it can be value saved at the specified offset. When a string value is stretched, a blank position is 0 filled.

offsetparameter must be greater than or equal 0 to less than 2^32 (bit mapping is limited to within MB).

For large offset setbit operations, memory allocation may cause the Redis server to be blocked. Refer specifically to the SETRANGE command, Warning (warning) section.

3,bitop operation Destkey key [key ...]

A bitwise operation is performed on one or more strings that hold bits key , and the results are saved to the destkey top.

operationCan be AND ,,, OR any of NOT XOR these four operations:

  • BITOP AND destkey key [key ...], the logic is calculated for one or more, and the key results are saved to destkey .
  • BITOP OR destkey key [key ...], the logical OR of one or more key , and the result is saved to destkey .
  • BITOP XOR destkey key [key ...], the logical XOR of one or more key , and the result is saved to destkey .
  • BITOP NOT destkey key, the logic for the given is key not, and the result is saved to destkey .

In addition NOT to operations, other operations can accept one or more key as input.

4,bitop operation Destkey key [key ...]

A bitwise operation is performed on one or more strings that hold bits key , and the results are saved to the destkey top.

operationCan be AND ,,, OR any of NOT XOR these four operations:

  • BITOP AND destkey key [key ...], the logic is calculated for one or more, and the key results are saved to destkey .
  • BITOP OR destkey key [key ...], the logical OR of one or more key , and the result is saved to destkey .
  • BITOP XOR destkey key [key ...], the logical XOR of one or more key , and the result is saved to destkey .
  • BITOP NOT destkey key, the logic for the given is key not, and the result is saved to destkey .

In addition NOT to operations, other operations can accept one or more key as input.

Handling strings of different lengths

When Bitop handles strings of different lengths, the missing part of the shorter string is considered 0 .

Empty is key also considered to be a 0 string sequence of inclusions.

Reference: http://redisdoc.com/index.html

Redis bit operation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.