From dd874ab02db04853d4b5952712ab34693f9a93de Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 4 Jan 2023 08:19:36 +0100 Subject: Merging upstream version 1.13.0. Signed-off-by: Daniel Baumann --- iredis/data/commands/setbit.md | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'iredis/data/commands/setbit.md') diff --git a/iredis/data/commands/setbit.md b/iredis/data/commands/setbit.md index 6f3a553..e0b440b 100644 --- a/iredis/data/commands/setbit.md +++ b/iredis/data/commands/setbit.md @@ -1,23 +1,24 @@ Sets or clears the bit at _offset_ in the string value stored at _key_. The bit is either set or cleared depending on _value_, which can be either 0 or - 1. -When _key_ does not exist, a new string value is created. The string is grown to -make sure it can hold a bit at _offset_. The _offset_ argument is required to be -greater than or equal to 0, and smaller than 2^32 (this limits bitmaps to -512MB). When the string at _key_ is grown, added bits are set to 0. +When _key_ does not exist, a new string value is created. +The string is grown to make sure it can hold a bit at _offset_. +The _offset_ argument is required to be greater than or equal to 0, and smaller +than 2^32 (this limits bitmaps to 512MB). +When the string at _key_ is grown, added bits are set to 0. **Warning**: When setting the last possible bit (_offset_ equal to 2^32 -1) and the string value stored at _key_ does not yet hold a string value, or holds a small string value, Redis needs to allocate all intermediate memory which can -block the server for some time. On a 2010 MacBook Pro, setting bit number 2^32 --1 (512MB allocation) takes ~300ms, setting bit number 2^30 -1 (128MB -allocation) takes ~80ms, setting bit number 2^28 -1 (32MB allocation) takes -~30ms and setting bit number 2^26 -1 (8MB allocation) takes ~8ms. Note that once -this first allocation is done, subsequent calls to `SETBIT` for the same _key_ -will not have the allocation overhead. +block the server for some time. +On a 2010 MacBook Pro, setting bit number 2^32 -1 (512MB allocation) takes +~300ms, setting bit number 2^30 -1 (128MB allocation) takes ~80ms, setting bit +number 2^28 -1 (32MB allocation) takes ~30ms and setting bit number 2^26 -1 (8MB +allocation) takes ~8ms. +Note that once this first allocation is done, subsequent calls to `SETBIT` for +the same _key_ will not have the allocation overhead. @return @@ -40,13 +41,14 @@ be set. However, so as an optimization you can use a single `SET` command to set the entire bitmap. Bitmaps are not an actual data type, but a set of bit-oriented operations -defined on the String type (for more information refer to the [Bitmaps section -of the Data Types Introduction page][ti]). This means that bitmaps can be used -with string commands, and most importantly with `SET` and `GET`. +defined on the String type (for more information refer to the +[Bitmaps section of the Data Types Introduction page][ti]). This means that +bitmaps can be used with string commands, and most importantly with `SET` and +`GET`. Because Redis' strings are binary-safe, a bitmap is trivially encoded as a bytes -stream. The first byte of the string corresponds to offsets 0..7 of the bitmap, -the second byte to the 8..15 range, and so forth. +stream. The first byte of the string corresponds to offsets 0..7 of +the bitmap, the second byte to the 8..15 range, and so forth. For example, after setting a few bits, getting the string value of the bitmap would look like this: -- cgit v1.2.3