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: src/ds/strings.md
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@ Redis strings are used to store strings, numbers, images, serialized objects, an
2
2
3
3
As a first example, use the `SET` command to store the value "Deimos", a type of bike, at key "bike:1".
4
4
5
-
```redis Create a new key
5
+
```redis:[run_confirmation=true] Create a new key
6
6
SET bike:1 "Deimos"
7
7
```
8
8
@@ -23,7 +23,7 @@ The `EXISTS` command returns `1` when a key exists and `0` when it does not exis
23
23
24
24
Use the `DEL` to delete a key and its data.
25
25
26
-
```redis Delete bike:1
26
+
```redis:[run_confirmation=true] Delete bike:1
27
27
DEL bike:1
28
28
EXISTS bike:1
29
29
```
@@ -37,24 +37,24 @@ If you store integer data in a string key, you can use these commands to increme
37
37
-`DECR` - decrement a number stored in a key by `2`.
38
38
-`DECRBY` - decrement a number stored in a key by a specific positive or negative amount.
39
39
40
-
```redis INCR usage
40
+
```redis:[run_confirmation=true] INCR usage
41
41
SET bikes:total_number 10
42
42
INCR bikes:total_number
43
43
INCR bikes:total_number
44
44
```
45
45
46
-
```redis Use INCR to set a key to 1
46
+
```redis:[run_confirmation=true] Use INCR to set a key to 1
47
47
DEL bikes:total_number
48
48
INCR bikes:total_number
49
49
```
50
50
51
51
Note how the `INCR bikes:total_number` command that follows the `DEL` command re-creates the `bikes:total_number` key and sets its value to `1`.
52
52
53
-
```redis INCRBY usage
53
+
```redis:[run_confirmation=true] INCRBY usage
54
54
INCRBY bikes:total_number 100
55
55
```
56
56
57
-
```redis DECR and DECRBY usage
57
+
```redis:[run_confirmation=true] DECR and DECRBY usage
58
58
DECR bikes:total_number
59
59
DECRBY bikes:total_number 10
60
60
```
@@ -67,7 +67,7 @@ All the Redis operations implemented by single commands are atomic, including th
67
67
68
68
When keys are created without constraints, they live for the full lifespan of the Redis server to which they are attached. However, if you want a key to live for only a specific amount of time, you can use the `EXPIRE` command to alter its lifespan. To find out how much time is left before a key expires, use the `TTL` command.
69
69
70
-
```redis EXPIRE usage
70
+
```redis:[run_confirmation=true] EXPIRE usage
71
71
SET bike:1:lock_status "LOCKED"
72
72
EXPIRE bike:1:lock_status 20
73
73
```
@@ -85,7 +85,7 @@ You'll see one of the two return values:
85
85
86
86
If you try to use the `TTL` command on a key that does not have an expiration set, it will return `-1`.
87
87
88
-
```redis TTL on a non-expiring key
88
+
```redis:[run_confirmation=true] TTL on a non-expiring key
89
89
SET bike:2:lock_status "LOCKED"
90
90
TTL bike:2:lock_status
91
91
```
@@ -94,13 +94,13 @@ TTL bike:2:lock_status
94
94
95
95
The `SET` command can take additional arguments, one of which allows you to set the value of a key and its time to live value directly in a single, atomic operation. The `EX` and `PX` arguments allow you to specify the TTL value as either seconds or milliseconds, respectively.
96
96
97
-
```redis SET with time to live
97
+
```redis:[run_confirmation=true] SET with time to live
98
98
SET bike:1:lock_status "LOCKED" PX 1
99
99
```
100
100
101
101
It's possible to cancel a key's timeout using the `PERSIST` command.
0 commit comments