Skip to content

Commit 8cbda5b

Browse files
authored
DEV: Add TCEs to select command pages (#607)
* DOC-4040: (DOC-4076 & DOC-4077) changes for HSET and HGET commands * DOC-4040: (DOC-4078) changes for INCR command * DOC-4040: (DOC-4080) changes for INCR command * DOC-4040: (DOC-4081) changes for ZRANGE command * DOC-4040: (DOC-4082) changes for EXPIRE command * DOC-4040: (DOC-4083) changes for TTL command * DOC-4040: (DOC-4084) changes for DEL command * DOC-4040: (DOC-4079) changes for SCAN command
1 parent fed144a commit 8cbda5b

File tree

9 files changed

+175
-59
lines changed

9 files changed

+175
-59
lines changed

content/commands/del/index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ A key is ignored if it does not exist.
5757

5858
## Examples
5959

60+
{{< clients-example cmds_generic del >}}
61+
> SET key1 "Hello"
62+
"OK"
63+
> SET key2 "World"
64+
"OK"
65+
> DEL key1 key2 key3
66+
(integer) 2
67+
{{< /clients-example >}}
68+
69+
Give these commands a try in the interactive console:
70+
6071
{{% redis-cli %}}
6172
SET key1 "Hello"
6273
SET key2 "World"

content/commands/expire/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,29 @@ are now fixed.
137137

138138
## Examples
139139

140+
{{< clients-example cmds_generic expire >}}
141+
> SET mykey "Hello"
142+
"OK"
143+
> EXPIRE mykey 10
144+
(integer) 1
145+
> TTL mykey
146+
(integer) 10
147+
> SET mykey "Hello World"
148+
"OK"
149+
> TTL mykey
150+
(integer) -1
151+
> EXPIRE mykey 10 XX
152+
(integer) 0
153+
> TTL mykey
154+
(integer) -1
155+
> EXPIRE mykey 10 NX
156+
(integer) 1
157+
> TTL mykey
158+
(integer) 10
159+
{{< /clients-example >}}
160+
161+
Give these commands a try in the interactive console:
162+
140163
{{% redis-cli %}}
141164
SET mykey "Hello"
142165
EXPIRE mykey 10

content/commands/hget/index.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,19 @@ Returns the value associated with `field` in the hash stored at `key`.
5353

5454
## Examples
5555

56+
{{< clients-example cmds_hash hget >}}
57+
> HSET myhash field1 "foo"
58+
(integer) 1
59+
> HGET myhash field1
60+
"foo"
61+
> HGET myhash field2
62+
(nil)
63+
{{< /clients-example >}}
64+
65+
Give these commands a try in the interactive console:
66+
5667
{{% redis-cli %}}
5768
HSET myhash field1 "foo"
5869
HGET myhash field1
5970
HGET myhash field2
6071
{{% /redis-cli %}}
61-

content/commands/hset/index.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,33 @@ If `key` doesn't exist, a new key holding a hash is created.
6868

6969
## Examples
7070

71+
{{< clients-example cmds_hash hset >}}
72+
> HSET myhash field1 "Hello"
73+
(integer) 1
74+
> HGET myhash field1
75+
"Hello"
76+
> HSET myhash field2 "Hi" field3 "World"
77+
(integer) 2
78+
> HGET myhash field2
79+
"Hi"
80+
> HGET myhash field3
81+
"World"
82+
> HGETALL myhash
83+
1) "field1"
84+
2) "Hello"
85+
3) "field2"
86+
4) "Hi"
87+
5) "field3"
88+
6) "World"
89+
{{< /clients-example >}}
90+
91+
Give these commands a try in the interactive console:
92+
7193
{{% redis-cli %}}
7294
HSET myhash field1 "Hello"
7395
HGET myhash field1
7496
HSET myhash field2 "Hi" field3 "World"
7597
HGET myhash field2
7698
HGET myhash field3
7799
HGETALL myhash
78-
{{% /redis-cli %}}
79-
100+
{{% /redis-cli %}}

content/commands/incr/index.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,23 @@ representation of the integer.
6767

6868
## Examples
6969

70+
{{< clients-example cmds_string incr >}}
71+
> SET mykey "10"
72+
"OK"
73+
> INCR mykey
74+
(integer) 11
75+
> GET mykey
76+
"11"
77+
{{< /clients-example >}}
78+
79+
Give this command a try in the interactive console:
80+
7081
{{% redis-cli %}}
7182
SET mykey "10"
7283
INCR mykey
7384
GET mykey
7485
{{% /redis-cli %}}
7586

76-
7787
## Pattern: Counter
7888

7989
The counter pattern is the most obvious thing you can do with Redis atomic

content/commands/scan/index.md

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ SCAN is a cursor based iterator. This means that at every call of the command, t
7676
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:
7777

7878
```
79-
redis 127.0.0.1:6379> scan 0
79+
> scan 0
8080
1) "17"
8181
2) 1) "key:12"
8282
2) "key:8"
@@ -89,7 +89,7 @@ redis 127.0.0.1:6379> scan 0
8989
9) "key:3"
9090
10) "key:7"
9191
11) "key:1"
92-
redis 127.0.0.1:6379> scan 17
92+
> scan 17
9393
1) "0"
9494
2) 1) "key:5"
9595
2) "key:18"
@@ -155,33 +155,32 @@ To do so, just append the `MATCH <pattern>` arguments at the end of the `SCAN` c
155155

156156
This is an example of iteration using **MATCH**:
157157

158-
```
159-
redis 127.0.0.1:6379> sadd myset 1 2 3 foo foobar feelsgood
158+
{{< clients-example cmds_generic scan1 >}}
159+
> sadd myset 1 2 3 foo foobar feelsgood
160160
(integer) 6
161-
redis 127.0.0.1:6379> sscan myset 0 match f*
161+
> sscan myset 0 match f*
162162
1) "0"
163163
2) 1) "foo"
164164
2) "feelsgood"
165165
3) "foobar"
166-
redis 127.0.0.1:6379>
167-
```
166+
{{< /clients-example >}}
168167

169168
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:
170169

171-
```
172-
redis 127.0.0.1:6379> scan 0 MATCH *11*
170+
{{< clients-example cmds_generic scan2 >}}
171+
> scan 0 MATCH *11*
173172
1) "288"
174173
2) 1) "key:911"
175-
redis 127.0.0.1:6379> scan 288 MATCH *11*
174+
> scan 288 MATCH *11*
176175
1) "224"
177176
2) (empty list or set)
178-
redis 127.0.0.1:6379> scan 224 MATCH *11*
177+
> scan 224 MATCH *11*
179178
1) "80"
180179
2) (empty list or set)
181-
redis 127.0.0.1:6379> scan 80 MATCH *11*
180+
> scan 80 MATCH *11*
182181
1) "176"
183182
2) (empty list or set)
184-
redis 127.0.0.1:6379> scan 176 MATCH *11* COUNT 1000
183+
> scan 176 MATCH *11* COUNT 1000
185184
1) "0"
186185
2) 1) "key:611"
187186
2) "key:711"
@@ -201,8 +200,7 @@ redis 127.0.0.1:6379> scan 176 MATCH *11* COUNT 1000
201200
16) "key:811"
202201
17) "key:511"
203202
18) "key:11"
204-
redis 127.0.0.1:6379>
205-
```
203+
{{< /clients-example >}}
206204

207205
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.
208206

@@ -219,41 +217,41 @@ You can use the `TYPE` option to ask `SCAN` to only return objects that match a
219217

220218
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:
221219

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
224222
(integer) 1
225-
redis 127.0.0.1:6379> ZADD zkey 1000 value
223+
> ZADD zkey 1000 value
226224
(integer) 1
227-
redis 127.0.0.1:6379> TYPE geokey
225+
> TYPE geokey
228226
zset
229-
redis 127.0.0.1:6379> TYPE zkey
227+
> TYPE zkey
230228
zset
231-
redis 127.0.0.1:6379> SCAN 0 TYPE zset
229+
> SCAN 0 TYPE zset
232230
1) "0"
233231
2) 1) "geokey"
234232
2) "zkey"
235-
```
233+
{{< /clients-example >}}
236234

237235
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.
238236

239237
## The NOVALUES option
240238

241239
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.
242240

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
245243
OK
246-
redis 127.0.0.1:6379> HSCAN myhash 0
244+
> HSCAN myhash 0
247245
1) "0"
248246
2) 1) "a"
249247
2) "1"
250248
3) "b"
251249
4) "2"
252-
redis 127.0.0.1:6379> HSCAN myhash 0 NOVALUES
250+
> HSCAN myhash 0 NOVALUES
253251
1) "0"
254252
2) 1) "a"
255253
2) "b"
256-
```
254+
{{< /clients-example >}}
257255

258256
## Multiple parallel iterations
259257

@@ -292,15 +290,9 @@ For more information about managing keys, please refer to the [The Redis Keyspac
292290

293291
## Additional examples
294292

295-
Iteration of a Hash value.
293+
Give the following commands, showing iteration of a hash key, a try in the interactive console:
296294

297-
```
298-
redis 127.0.0.1:6379> hmset hash name Jack age 33
299-
OK
300-
redis 127.0.0.1:6379> hscan hash 0
301-
1) "0"
302-
2) 1) "name"
303-
2) "Jack"
304-
3) "age"
305-
4) "33"
306-
```
295+
{{% redis-cli %}}
296+
HMSET hash name Jack age 33
297+
HSCAN hash 0
298+
{{% /redis-cli %}}

content/commands/ttl/index.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,19 @@ See also the [`PTTL`]({{< relref "/commands/pttl" >}}) command that returns the
6666

6767
## Examples
6868

69+
{{< clients-example cmds_generic ttl >}}
70+
> SET mykey "Hello"
71+
"OK"
72+
> EXPIRE mykey 10
73+
(integer) 1
74+
> TTL mykey
75+
(integer) 10
76+
{{< /clients-example >}}
77+
78+
Give these commands a try in the interactive console:
79+
6980
{{% redis-cli %}}
7081
SET mykey "Hello"
7182
EXPIRE mykey 10
7283
TTL mykey
7384
{{% /redis-cli %}}
74-

content/commands/zadd/index.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,29 @@ If the user inserts all the elements in a sorted set with the same score (for ex
168168

169169
## Examples
170170

171+
{{< clients-example cmds_sorted_set zadd >}}
172+
> ZADD myzset 1 "one"
173+
(integer) 1
174+
> ZADD myzset 1 "uno"
175+
(integer) 1
176+
> ZADD myzset 2 "two" 3 "three"
177+
(integer) 2
178+
> ZRANGE myzset 0 -1 WITHSCORES
179+
1) "one"
180+
2) "1"
181+
3) "uno"
182+
4) "1"
183+
5) "two"
184+
6) "2"
185+
7) "three"
186+
8) "3"
187+
{{< /clients-example >}}
188+
189+
Give these commands a try in the interactive console:
190+
171191
{{% redis-cli %}}
172192
ZADD myzset 1 "one"
173193
ZADD myzset 1 "uno"
174194
ZADD myzset 2 "two" 3 "three"
175195
ZRANGE myzset 0 -1 WITHSCORES
176196
{{% /redis-cli %}}
177-

content/commands/zrange/index.md

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,26 +196,46 @@ The binary nature of the comparison allows to use sorted sets as a general purpo
196196

197197
## Examples
198198

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 >}}
206212

207213
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*.
208214

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 >}}
214224

215225
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:
216226

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:
235+
217236
{{% redis-cli %}}
218237
ZADD myzset 1 "one" 2 "two" 3 "three"
219-
ZRANGE myzset (1 +inf BYSCORE LIMIT 1 1
220-
{{% /redis-cli %}}
221-
238+
ZRANGE myzset 0 -1
239+
ZRANGE myzset 2 3
240+
ZRANGE myzset -2 -1
241+
{{% /redis-cli %}}

0 commit comments

Comments
 (0)