Skip to content

Commit c176d2b

Browse files
committed
DOC-5367: update bitmap docs for ROS8.2
1 parent a07a654 commit c176d2b

File tree

2 files changed

+57
-10
lines changed

2 files changed

+57
-10
lines changed

content/commands/bitop.md

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ arguments:
2121
name: not
2222
token: NOT
2323
type: pure-token
24+
- display_text: diff
25+
name: diff
26+
token: DIFF
27+
type: pure-token
28+
- display_text: diff1
29+
name: diff1
30+
token: DIFF1
31+
type: pure-token
32+
- display_text: andor
33+
name: andor
34+
token: ANDOR
35+
type: pure-token
36+
- display_text: one
37+
name: one
38+
token: ONE
39+
type: pure-token
2440
name: operation
2541
type: oneof
2642
- display_text: destkey
@@ -78,26 +94,45 @@ key_specs:
7894
linkTitle: BITOP
7995
since: 2.6.0
8096
summary: Performs bitwise operations on multiple strings, and stores the result.
81-
syntax_fmt: BITOP <AND | OR | XOR | NOT> destkey key [key ...]
97+
syntax_fmt: "BITOP <AND | OR | XOR | NOT | DIFF | DIFF1 | ANDOR | ONE> destkey key [key ...]"
8298
syntax_str: destkey key [key ...]
8399
title: BITOP
84100
---
85101
Perform a bitwise operation between multiple keys (containing string values) and
86102
store the result in the destination key.
87103

88-
The `BITOP` command supports four bitwise operations: **AND**, **OR**, **XOR**
89-
and **NOT**, thus the valid forms to call the command are:
104+
The `BITOP` command supports eight bitwise operations: `AND`, `OR`, `XOR`,
105+
`NOT`, `DIFF`, `DIFF1`, `ANDOR`, and `ONE`. The valid forms to call the command are:
90106

91107

92108
* `BITOP AND destkey srckey1 srckey2 srckey3 ... srckeyN`
109+
110+
A bit in `destkey` is set only if it is set in all source bitmaps.
93111
* `BITOP OR destkey srckey1 srckey2 srckey3 ... srckeyN`
112+
113+
A bit in `destkey` is set only if it is set in at least one source bitmap.
94114
* `BITOP XOR destkey srckey1 srckey2 srckey3 ... srckeyN`
115+
116+
Mostly used with two source bitmaps, a bit in `destkey` is set only if its value differs between the two source bitmaps.
95117
* `BITOP NOT destkey srckey`
96118

97-
As you can see **NOT** is special as it only takes an input key, because it
98-
performs inversion of bits so it only makes sense as a unary operator.
119+
`NOT` is a unary operator and only supports a single source bitmap; set the bit to the inverse of its value in the source bitmap.
120+
* `BITOP DIFF destkey X [Y1 Y2 ...]` <sup>[1](#list-note-1)</sup>
121+
122+
A bit in `destkey` is set if it is set in `X`, but not in any of `Y1, Y2, ...` .
123+
* `BITOP DIFF1 destkey X [Y1 Y2 ...]` <sup>[1](#list-note-1)</sup>
99124

100-
The result of the operation is always stored at `destkey`.
125+
A bit in `destkey` is set if it is set in one or more of `Y1, Y2, ...`, but not in `X`.
126+
* `BITOP ANDOR destkey X [Y1 Y2 ...]` <sup>[1](#list-note-1)</sup>
127+
128+
A bit in `destkey` is set if it is set in `X` and also in one or more of `Y1, Y2, ...`.
129+
* `BITOP ONE destkey X1 [X2 X3 ...]` <sup>[1](#list-note-1)</sup>
130+
131+
A bit in `destkey` is set if it is set in exactly one of `X1, X2, ...`.
132+
133+
The result of each operation is always stored at `destkey`.
134+
135+
1. <a name="list-note-1"></a> Added in Redis 8.2.
101136

102137
## Handling of strings with different lengths
103138

@@ -110,13 +145,27 @@ zero bytes up to the length of the longest string.
110145

111146
## Examples
112147

148+
1. Basic usage example using the `AND` operator:
149+
113150
{{% redis-cli %}}
114151
SET key1 "foobar"
115152
SET key2 "abcdef"
116153
BITOP AND dest key1 key2
117154
GET dest
118155
{{% /redis-cli %}}
119156

157+
2. Suppose you want to expose people to a book-related ad. The target audience is people who love to read books and are interested in fantasy, adventure, or science fiction. Assume you have the following bitmaps:
158+
159+
* `LRB` - people who love to read books.
160+
* `B:F` - people interested in fantasy.
161+
* `B:A` - people interested in adventure.
162+
* `B:SF` - people interested in science fiction.
163+
164+
To create a bitmap representing the target audience, use the following command:
165+
166+
```
167+
BITOP ANDOR newkey LRB B:F B:A B:SF
168+
```
120169

121170
## Pattern: real time metrics using bitmaps
122171

content/develop/data-types/bitmaps.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ categories:
99
- oss
1010
- kubernetes
1111
- clients
12-
description: 'Introduction to Redis bitmaps
13-
14-
'
12+
description: Introduction to Redis bitmaps
1513
linkTitle: Bitmaps
1614
title: Redis bitmaps
1715
weight: 120
@@ -79,7 +77,7 @@ stored into the target key) are always considered to be zero.
7977

8078
There are three commands operating on group of bits:
8179

82-
1. [`BITOP`]({{< relref "/commands/bitop" >}}) performs bit-wise operations between different strings. The provided operations are AND, OR, XOR and NOT.
80+
1. [`BITOP`]({{< relref "/commands/bitop" >}}) performs bit-wise operations between different strings. The provided operators are `AND`, `OR`, `XOR`, `NOT`, `DIFF`, `DIFF1`, `ANDOR`, and `ONE`.
8381
2. [`BITCOUNT`]({{< relref "/commands/bitcount" >}}) performs population counting, reporting the number of bits set to 1.
8482
3. [`BITPOS`]({{< relref "/commands/bitpos" >}}) finds the first bit having the specified value of 0 or 1.
8583

0 commit comments

Comments
 (0)