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
Copy file name to clipboardExpand all lines: content/commands/scan/index.md
+30-38Lines changed: 30 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,7 +76,7 @@ SCAN is a cursor based iterator. This means that at every call of the command, t
76
76
An iteration starts when the cursor is set to 0, and terminates when the cursor returned by the server is 0. The following is an example of SCAN iteration:
77
77
78
78
```
79
-
redis 127.0.0.1:6379> scan 0
79
+
> scan 0
80
80
1) "17"
81
81
2) 1) "key:12"
82
82
2) "key:8"
@@ -89,7 +89,7 @@ redis 127.0.0.1:6379> scan 0
89
89
9) "key:3"
90
90
10) "key:7"
91
91
11) "key:1"
92
-
redis 127.0.0.1:6379> scan 17
92
+
> scan 17
93
93
1) "0"
94
94
2) 1) "key:5"
95
95
2) "key:18"
@@ -155,33 +155,32 @@ To do so, just append the `MATCH <pattern>` arguments at the end of the `SCAN` c
It is important to note that the **MATCH** filter is applied after elements are retrieved from the collection, just before returning data to the client. This means that if the pattern matches very little elements inside the collection, `SCAN` will likely return no elements in most iterations. An example is shown below:
170
169
171
-
```
172
-
redis 127.0.0.1:6379> scan 0 MATCH *11*
170
+
{{< clients-example cmds_generic scan2 >}}
171
+
> scan 0 MATCH *11*
173
172
1) "288"
174
173
2)1) "key:911"
175
-
redis 127.0.0.1:6379> scan 288 MATCH *11*
174
+
> scan 288 MATCH *11*
176
175
1) "224"
177
176
2) (empty list or set)
178
-
redis 127.0.0.1:6379> scan 224 MATCH *11*
177
+
> scan 224 MATCH *11*
179
178
1) "80"
180
179
2) (empty list or set)
181
-
redis 127.0.0.1:6379> scan 80 MATCH *11*
180
+
> scan 80 MATCH *11*
182
181
1) "176"
183
182
2) (empty list or set)
184
-
redis 127.0.0.1:6379> scan 176 MATCH *11* COUNT 1000
As you can see most of the calls returned zero elements, but the last call where a `COUNT` of 1000 was used in order to force the command to do more scanning for that iteration.
208
206
@@ -219,41 +217,41 @@ You can use the `TYPE` option to ask `SCAN` to only return objects that match a
219
217
220
218
The `type` argument is the same string name that the [`TYPE`]({{< relref "/commands/type" >}}) command returns. Note a quirk where some Redis types, such as GeoHashes, HyperLogLogs, Bitmaps, and Bitfields, may internally be implemented using other Redis types, such as a string or zset, so can't be distinguished from other keys of that same type by `SCAN`. For example, a ZSET and GEOHASH:
221
219
222
-
```
223
-
redis 127.0.0.1:6379> GEOADD geokey 0 0 value
220
+
{{< clients-example cmds_generic scan3 >}}
221
+
> GEOADD geokey 0 0 value
224
222
(integer) 1
225
-
redis 127.0.0.1:6379> ZADD zkey 1000 value
223
+
> ZADD zkey 1000 value
226
224
(integer) 1
227
-
redis 127.0.0.1:6379> TYPE geokey
225
+
> TYPE geokey
228
226
zset
229
-
redis 127.0.0.1:6379> TYPE zkey
227
+
> TYPE zkey
230
228
zset
231
-
redis 127.0.0.1:6379> SCAN 0 TYPE zset
229
+
> SCAN 0 TYPE zset
232
230
1) "0"
233
231
2)1) "geokey"
234
232
2) "zkey"
235
-
```
233
+
{{< /clients-example >}}
236
234
237
235
It is important to note that the **TYPE** filter is also applied after elements are retrieved from the database, so the option does not reduce the amount of work the server has to do to complete a full iteration, and for rare types you may receive no elements in many iterations.
238
236
239
237
## The NOVALUES option
240
238
241
239
When using [`HSCAN`]({{< relref "/commands/hscan" >}}), you can use the `NOVALUES` option to make Redis return only the keys in the hash table without their corresponding values.
242
240
243
-
```
244
-
redis 127.0.0.1:6379> HSET myhash a 1 b 2
241
+
{{< clients-example cmds_generic scan4 >}}
242
+
> HSET myhash a 1 b 2
245
243
OK
246
-
redis 127.0.0.1:6379> HSCAN myhash 0
244
+
> HSCAN myhash 0
247
245
1) "0"
248
246
2)1) "a"
249
247
2) "1"
250
248
3) "b"
251
249
4) "2"
252
-
redis 127.0.0.1:6379> HSCAN myhash 0 NOVALUES
250
+
> HSCAN myhash 0 NOVALUES
253
251
1) "0"
254
252
2)1) "a"
255
253
2) "b"
256
-
```
254
+
{{< /clients-example >}}
257
255
258
256
## Multiple parallel iterations
259
257
@@ -292,15 +290,9 @@ For more information about managing keys, please refer to the [The Redis Keyspac
292
290
293
291
## Additional examples
294
292
295
-
Iteration of a Hash value.
293
+
Give the following commands, showing iteration of a hash key, a try in the interactive console:
Copy file name to clipboardExpand all lines: content/commands/zrange/index.md
+35-15Lines changed: 35 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -196,26 +196,46 @@ The binary nature of the comparison allows to use sorted sets as a general purpo
196
196
197
197
## Examples
198
198
199
-
{{% redis-cli %}}
200
-
ZADD myzset 1 "one" 2 "two" 3 "three"
201
-
ZRANGE myzset 0 -1
202
-
ZRANGE myzset 2 3
203
-
ZRANGE myzset -2 -1
204
-
{{% /redis-cli %}}
205
-
199
+
{{< clients-example cmds_sorted_set zrange1 >}}
200
+
> ZADD myzset 1 "one" 2 "two" 3 "three"
201
+
(integer) 3
202
+
> ZRANGE myzset 0 -1
203
+
1) "one"
204
+
2) "two"
205
+
3) "three"
206
+
> ZRANGE myzset 2 3
207
+
1) "three"
208
+
> ZRANGE myzset -2 -1
209
+
1) "two"
210
+
2) "three"
211
+
{{< /clients-example >}}
206
212
207
213
The following example using `WITHSCORES` shows how the command returns always an array, but this time, populated with *element_1*, *score_1*, *element_2*, *score_2*, ..., *element_N*, *score_N*.
208
214
209
-
{{% redis-cli %}}
210
-
ZADD myzset 1 "one" 2 "two" 3 "three"
211
-
ZRANGE myzset 0 1 WITHSCORES
212
-
{{% /redis-cli %}}
213
-
215
+
{{< clients-example cmds_sorted_set zrange2 >}}
216
+
> ZADD myzset 1 "one" 2 "two" 3 "three"
217
+
(integer) 3
218
+
> ZRANGE myzset 0 1 WITHSCORES
219
+
1) "one"
220
+
2) "1"
221
+
3) "two"
222
+
4) "2"
223
+
{{< /clients-example >}}
214
224
215
225
This example shows how to query the sorted set by score, excluding the value `1` and up to infinity, returning only the second element of the result:
216
226
227
+
{{< clients-example cmds_sorted_set zrange3 >}}
228
+
> ZADD myzset 1 "one" 2 "two" 3 "three"
229
+
(integer) 3
230
+
> ZRANGE myzset (1 +inf BYSCORE LIMIT 1 1
231
+
1) "three"
232
+
{{< /clients-example >}}
233
+
234
+
Give these commands a try in the interactive console:
0 commit comments