Realization of switch configuration function based on Redis bitmap

Source: Internet
Author: User

zhanhailiang 日期:2014-12-21
Bitmap API

Setbit Key Offset value
Sets or clears a bit (bit) on the specified offset for the string value stored by key.
The setting or clearing of bits depends on the value parameter, which can be 0 or 1.
When key does not exist, you are actively generating a new string value.
The string is stretched (grown) to ensure that it is able to save value at the specified offset.
When the string value is stretched, the blank position is filled with 0.
The offset parameter must be greater than or equal to 0, less than 2^32 (bit mapping is limited to 512MB).
Return value: Specifies the bit that the offset was originally stored in.
Warning: For setbit operations that use large offset, memory allocation can cause Redisserver to be blocked.
Warning: When generating a very long string, Redis needs to allocate memory space, which can sometimes
Causes the server to Jam (block). On the 2010 MacBook Pro, set the offset to 536870911 (within 512MB
300 milliseconds, set the offset to 134217728 (128MB memory allocation), consumes about 80 milliseconds,
Sets the offset 33554432 (32MB memory allocation), consumes about 30 milliseconds, sets the offset to 8388608 (8MB memory allocation),
Consumes about 8 milliseconds.

Getbit Key Offset
Gets the bit on the specified offset for the string value stored by key.
Returns 0 when offset is greater than the length of the string value, or if the key does not exist.
Return value: The string value specifies the bit on the offset (bit).

Demand Scenarios

In very many business scenarios, we need to implement configurations for very versatile implementations, such as the following scenario:

    1. Add a feature, want to have a switch to control whether to turn on the function;
    2. Game on-Line a new feature, want to guide users to open the function, the need to induce users, for example, to open the function, to obtain XX reward, at this time need to mark a bit to record the prize record;
Code implementation

https://github.com/billfeller/billfeller.github.io/blob/master/code/IBit.php

Realization of switch configuration function based on Redis bitmap

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.