You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mostly used with two source bitmaps, a bit in `destkey` is set only if its value differs between the two source bitmaps.
95
117
*`BITOP NOT destkey srckey`
96
118
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>
99
124
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. <aname="list-note-1"></a> Added in Redis 8.2.
101
136
102
137
## Handling of strings with different lengths
103
138
@@ -110,13 +145,27 @@ zero bytes up to the length of the longest string.
110
145
111
146
## Examples
112
147
148
+
1. Basic usage example using the `AND` operator:
149
+
113
150
{{% redis-cli %}}
114
151
SET key1 "foobar"
115
152
SET key2 "abcdef"
116
153
BITOP AND dest key1 key2
117
154
GET dest
118
155
{{% /redis-cli %}}
119
156
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:
Copy file name to clipboardExpand all lines: content/develop/data-types/bitmaps.md
+2-4Lines changed: 2 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -9,9 +9,7 @@ categories:
9
9
- oss
10
10
- kubernetes
11
11
- clients
12
-
description: 'Introduction to Redis bitmaps
13
-
14
-
'
12
+
description: Introduction to Redis bitmaps
15
13
linkTitle: Bitmaps
16
14
title: Redis bitmaps
17
15
weight: 120
@@ -79,7 +77,7 @@ stored into the target key) are always considered to be zero.
79
77
80
78
There are three commands operating on group of bits:
81
79
82
-
1.[`BITOP`]({{< relref "/commands/bitop" >}}) performs bit-wise operations between different strings. The provided operations are AND, OR, XORand 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`.
83
81
2.[`BITCOUNT`]({{< relref "/commands/bitcount" >}}) performs population counting, reporting the number of bits set to 1.
84
82
3.[`BITPOS`]({{< relref "/commands/bitpos" >}}) finds the first bit having the specified value of 0 or 1.
0 commit comments