Skip to content

Commit f824b42

Browse files
committed
DOC-3100: more re-org and additional content
1 parent 02beeb0 commit f824b42

8 files changed

+110
-56
lines changed

src/manifest.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"children": [
1010
{
1111
"type": "group",
12-
"id": "redis",
13-
"label": "Redis",
12+
"id": "redis_basic",
13+
"label": "Basic data structures",
1414
"args": {
1515
"initialIsOpen": false
1616
},
@@ -75,8 +75,8 @@
7575
},
7676
{
7777
"type": "group",
78-
"id": "redis_stack",
79-
"label": "Redis Stack",
78+
"id": "redis_advanced",
79+
"label": "Advanced data structures",
8080
"args": {
8181
"initialIsOpen": false
8282
},

src/redis/introduction.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
In this set of tutorials, you will be introduced to the following set of Redis data structure types using a hypothetical bike shop use case:
22

3-
- [strings](https://redis.io/docs/data-types/strings)
4-
- [lists](https://redis.io/docs/data-types/lists)
5-
- [sets](https://redis.io/docs/data-types/sets)
6-
- [sorted sets](https://redis.io/docs/data-types/sorted-sets)
7-
- [hashes](https://redis.io/docs/data-types/hashes)
3+
- strings - used for storing sequences of bytes, including text, images, and serialized objects.
4+
- lists - ordered linked lists of string values that can be used to implement stacks (LIFO), queues (FIFO), producer-consumer patterns, and more.
5+
- sets - unordered collections of unique strings that can be used to represent relations and track unique items.
6+
- sorted sets - collections of unique strings, which are ordered by an associated score, that can be used for rate limiters and game leaderboards.
7+
- hashes - record types, structured as collections of field-value pairs, used to represent objects.

src/redis/learn_more.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
In these general Redis tutorials, you've been introduced to Redis string, list, set, sorted set, and hash data structure types.
1+
In these Redis basic commands tutorials, you've been introduced to the Redis string, list, set, sorted set, and hash data structure types.
22
There are many more Redis data structure types that you can use for a variety of use cases. See [the Redis documentation](https://redis.io/docs/data-types) for the entire list of supported data types.

src/redis/working_with_hashes.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,47 @@
1-
Lists, sets, and sorted sets are great for many use cases, but the [hash](https://redis.io/docs/data-types/hashes) data type is on a higher level. Redis hashes are maps (sequences of key-value pairs) and are used to represent objects in Redis. Consider the following example that shows how to create a hash key using the [HSET](https://redis.io/commands/hset) command.
1+
Lists, sets, and sorted sets are great for many use cases, but the hash data type is on a higher level. Redis hashes are maps (sequences of field-value pairs) and are used to represent objects in Redis. Consider the following example that shows how to create a hash key using the `HSET` command.
22

33
```redis Create a hash
44
HSET bike:1 model Deimos brand Ergonom type "Enduro bikes" price 4972
55
```
66

77
`HSET` returns the number of added key/value pairs.
88

9-
To retrieve the stored data, use the [HGETALL](https://redis.io/commands/hgetall) command.
9+
To retrieve the stored data, use the `HGETALL` command.
1010

1111
```redis HGETALL usage
12-
HGETALL bike:1
12+
HGETALL bike:1 // returns all the field-value pairs associated with the key
1313
```
1414

15-
If you only want the values of a subset of the fields, use the [HGET](https://redis.io/commands/hget) command.
15+
If you only want the values of a subset of the fields, use the `HGET` command.
1616

1717
```redis HGET usage
1818
HGET bike:1 price
1919
```
2020

21-
Numerical values in hash keys can be incremented in the same way as simple string keys using the [HINCRBY](https://redis.io/commands/hincrby) command.
21+
You can update fields in a hash using `HSET` by specifying a subset of its field-value pairs.
22+
23+
```redis Update an existing hash
24+
HSET bike:1 model "Kraken" price 3000
25+
```
26+
27+
Use the `HDEL` command to delete one or more fields from a hash. Once all fields are removed, the hash key itself will be deleted.
28+
29+
```redis Delete hash fields and keys
30+
HDEL bike:1 model
31+
HGETALL bike:1
32+
HDEL bike:1 brand type price
33+
HGETALL bike:1
34+
EXISTS bike:1
35+
```
36+
37+
Numerical values in hash keys can be incremented in the same way as simple string keys using the `HINCRBY` command.
2238

2339
```redis Hash INCRBY usage
2440
HINCRBY bike:1 price 100
2541
HINCRBY bike:1 price -100
2642
```
2743

28-
See [here](https://redis.io/commands/?group=hash) for the entire set of Redis hash-related commands.
44+
See [here](https://redis.io/docs/data-types/hashes) for the hash type reference page, and [here](https://redis.io/commands/?group=hash) for the entire set of Redis hash commands.
2945

3046
**Note**:
3147
> If you're more familiar with JSON and want to use it with Redis, there is a [JSON data type](https://redis.io/docs/data-types/json) that is provided as part of Redis Stack. There's also a tutorial titled "Working with JSON" that is bundled with RedisInsight.

src/redis/working_with_lists.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
A Redis [list](https://redis.io/docs/data-types/lists) is a data type that contains a series of ordered values. You interact with lists using commands such as:
1+
A Redis list is a data type that contains a series of ordered string values. Use cases include
22

3-
- [RPUSH](https://redis.io/commands/rpush) - adds items to the end of a list.
4-
- [LPUSH](https://redis.io/commands/lpush) - adds items to the beginning of a list.
5-
- [LLEN](https://redis.io/commands/llen) - retrieves the length of a list.
6-
- [LRANGE](https://redis.io/commands/lrange) - retrieves list items from a specified range.
7-
- [LPOP](https://redis.io/commands/lpop) - removes and returns an item from the beginning of a list.
8-
- [RPOP](https://redis.io/commands/rpop) - removes and returns an item from the end of a list.
3+
- implementing stacks (LIFO data structures)
4+
- implementing queues (FIFO data structures)
5+
- implementing producer-consumer patterns
6+
7+
You interact with lists using commands such as:
8+
9+
- RPUSH - adds items to the end of a list.
10+
- LPUSH - adds items to the beginning of a list.
11+
- LLEN - retrieves the length of a list.
12+
- LRANGE - retrieves list items from a specified range.
13+
- LPOP - removes and returns an item from the beginning of a list.
14+
- RPOP - removes and returns an item from the end of a list.
915

1016
You can begin working with a list without first creating its key, simply by adding values to the key. This works as long as the key doesn't already exist as a different type.
1117

@@ -72,4 +78,4 @@ KEYS bike:colors
7278
**Note**:
7379
> `LRANGE` will return an empty (null) list if a key no longer exists.
7480
75-
See [here](https://redis.io/commands/?group=list) for the entire set of Redis list-related commands.
81+
See [here](https://redis.io/docs/data-types/list) for the list type reference page, and [here](https://redis.io/commands/?group=list) for the entire set of Redis list commands.

src/redis/working_with_sets.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
Redis [sets](https://redis.io/docs/data-types/sets/) are similar to lists, except they are unordered, and each element must be unique. You can use sets to:
1+
Redis sets are similar to lists, except they are unordered, and each element must be unique. You can use sets to:
22

33
- Track unique items (e.g., track all unique IP addresses accessing a given blog post).
44
- Represent relations (e.g., the set of all users with a specified role).
55
- Perform common set operations such as intersection, union, and difference.
66

77
Here are some important set commands:
88

9-
- [SADD](https://redis.io/commands/sadd)
10-
- [SREM](https://redis.io/commands/srem)
11-
- [SISMEMBER](https://redis.io/commands/sismember)
12-
- [SMEMBERS](https://redis.io/commands/smembers)
13-
- [SUNION](https://redis.io/commands/sunion)
9+
- `SADD`
10+
- `SREM`
11+
- `SISMEMBER`
12+
- `SMEMBERS`
13+
- `SUNION`
1414

1515
Use `SADD` to create and update a set. Each `SADD` command will return the number of added members. If you try to add a member that is already in the set, `0` is returned.
1616

@@ -22,7 +22,7 @@ SADD bike:1:addons "bell"
2222

2323
Notice that the `SADD` command is variadic.
2424

25-
`SREM` is used to remove members of a list. It returns `1` if the member is in the set, or `0` if it is not.
25+
`SREM` is used to remove members of a set. It returns `1` if the member is in the set, or `0` if it is not.
2626

2727
```redis Remove set members
2828
SREM bike:1:addons "bell"
@@ -51,8 +51,8 @@ SUNION bike:1:addons bike:1:special_addons
5151

5252
Sets have two ways to return one or more random members of a set:
5353

54-
- [SPOP](https://redis.io/commands/spop)
55-
- [SRANDMEMBER](https://redis.io/commands/srandmember)
54+
- `SPOP`
55+
- `SRANDMEMBER`
5656

5757
Each command takes a key and, optionally, a count as arguments. `SPOP` removes and returns a random member, whereas `SRANDMEMBER` just returns the randomly selected members without removing them.
5858

@@ -63,4 +63,4 @@ SPOP bike:1:addons
6363
SMEMBERS bike:1:addons
6464
```
6565

66-
See [here](https://redis.io/commands/?group=set) for the entire list of Redis set-related commands.
66+
See [here](https://redis.io/docs/data-types/sets) for the set type reference page, and [here](https://redis.io/commands/?group=set) for the entire list of Redis set commands.

src/redis/working_with_sorted_sets.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
Redis sets are unsorted, which limits their usefulness. [Sorted sets](https://redis.io/docs/data-types/sorted-sets) are similar to sets, except each unique member has an associated score, which provides the mechanism for sorting.
1+
Redis sets are unsorted, which limits their usefulness. Sorted sets are similar to sets, except each unique member has an associated score, which provides the mechanism for sorting. Use cases include:
2+
3+
- rate limiters
4+
- game leaderboards
25

36
The following example creates a set of bike brands named for famous computer programmers, using their birth year as the score element to sort the set.
47

@@ -13,12 +16,32 @@ ZADD bike:brands 1957 "Sophie Wilson"
1316
ZADD bike:brands 1912 "Alan Turing"
1417
```
1518

16-
Now you can use the [ZRANGE](https://redis.io/commands/zrange) command to retrieve members in the order of birth year.
19+
Now you can use the `ZRANGE` command to retrieve members in the order of birth year using member ranks as the arguments. As with lists, you can use `-1`, `-2`, etc., to represent the last, second to last, etc., members.
1720

1821
```redis ZRANGE usage
1922
ZRANGE bike:brands 2 4
2023
```
2124

22-
A popular use case for sorted sets is leaderboards for games.
25+
To delete members from a sorted set, use the `ZREM` command.
26+
27+
```redis Remove the Alan Turing model and score
28+
ZREM bike:brands "Alan Turing"
29+
```
30+
31+
Once all the members of a sorted set have been removed, the set's key will also be removed.
32+
33+
To list all the members in score order, use the `ZRANGEBYSCORE`. If you pass the `WITHSCORES` argument, each member's score will also be listed.
34+
35+
```redis List members ordered by score
36+
ZRANGEBYSCORE bike:brands -inf +inf WITHSCORES
37+
```
38+
39+
Note the use of `-inf` and `+inf` in the previous example. This is useful when you don't readily know the score range or particular values. See the manual page for `ZRANGEBYSCORE` for more options.
40+
41+
You can get the rank of any sorted set member using the `ZRANK` command. Note: the member with the lowest score has rank `0`.
42+
43+
```redis Get a bike brand's rank
44+
ZRANK bike:brands "Claude Shannon" WITHSCORE
45+
```
2346

24-
See [here](https://redis.io/commands/?group=sorted-set) for the entire list of Redis sorted set commands.
47+
See [here](https://redis.io/docs/data-types/sorted-sets) for the sorted set type reference page, and [here](https://redis.io/commands/?group=sorted-set) for the entire list of Redis sorted set commands.

src/redis/working_with_strings.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
Redis [strings](https://redis.io/docs/data-types/strings) are used to store strings, numbers, and other kinds of information. They are the simplest of the Redis data types.
1+
Redis strings are used to store strings, numbers, images, serialized objects, and other kinds of information. They are the simplest of the Redis data types.
22

3-
As a first example, use the [SET](https://redis.io/commands/set/) command to store the value "Deimos", a type of bike, at key "bike:1".
3+
As a first example, use the `SET` command to store the value "Deimos", a type of bike, at key "bike:1".
44

55
```redis Create a new key
66
SET bike:1 "Deimos"
77
```
88

9-
Redis will store the `bike:1` data permanently. You can retrieve the data using the [GET](https://redis.io/commands/get/) command.
9+
You can retrieve the data using the `GET` command.
1010

1111
```redis Retrieve the data
1212
GET bike:1
1313
```
1414

15-
To see if a key exists, use the [EXISTS](https://redis.io/commands/exists) command.
15+
To see if a key exists, use the `EXISTS` command.
1616

1717
```redis Do these keys exist?
1818
EXISTS bike:1
@@ -21,29 +21,40 @@ EXISTS bike:2
2121

2222
The `EXISTS` command returns `1` when a key exists and `0` when it does not exist. The `bike:1` key exists, so Redis returns a value of `1`. The `bike:2` key does not exist, so Redis returns `0`.
2323

24-
Use the [DEL](https://redis.io/commands/del) to delete a key and its data.
24+
Use the `DEL` to delete a key and its data.
25+
26+
```redis Delete bike:1
27+
DEL bike:1
28+
EXISTS bike:1
29+
```
2530

2631
## Strings as counters
2732

2833
If you store integer data in a string key, you can use these commands to increment and decrement its value:
2934

30-
- [INCR](https://redis.io/commands/incr) - increment a number stored in a key by `1`.
31-
- [INCRBY](https://redis.io/commands/incrby) - increment a number stored in a key by a specific positive or negative amount.
32-
- [DECR](https://redis.io/commands/decr) - decrement a number stored in a key by `2`.
33-
- [DECRBY](https://redis.io/commands/decrby) - decrement a number stored in a key by a specific positive or negative amount.
35+
- `INCR` - increment a number stored in a key by `1`.
36+
- `INCRBY` - increment a number stored in a key by a specific positive or negative amount.
37+
- `DECR` - decrement a number stored in a key by `2`.
38+
- `DECRBY` - decrement a number stored in a key by a specific positive or negative amount.
3439

35-
```redis INCR and DEL usage
40+
```redis INCR usage
3641
SET bikes:total_number 10
3742
INCR bikes:total_number
3843
INCR bikes:total_number
44+
```
45+
46+
```redis Use INCR to set a key to 1
3947
DEL bikes:total_number
4048
INCR bikes:total_number
4149
```
4250

4351
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`.
4452

45-
```redis INCRBY, DECR, and DECRBY usage
53+
```redis INCRBY usage
4654
INCRBY bikes:total_number 100
55+
```
56+
57+
```redis DECR and DECRBY usage
4758
DECR bikes:total_number
4859
DECRBY bikes:total_number 10
4960
```
@@ -54,11 +65,11 @@ All the Redis operations implemented by single commands are atomic, including th
5465

5566
## Key expiration
5667

57-
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](https://redis.io/commands/expire) command to alter its lifespan. To find out how much time is left before a key expires, use the [TTL](https://redis.io/commands/ttl) command.
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.
5869

5970
```redis EXPIRE usage
6071
SET bike:1:lock_status "LOCKED"
61-
EXPIRE bike:1:lock_status 120
72+
EXPIRE bike:1:lock_status 20
6273
```
6374

6475
After a few seconds, check the time-to-live status by running the `TTL` command.
@@ -79,22 +90,20 @@ SET bike:2:lock_status "LOCKED"
7990
TTL bike:2:lock_status
8091
```
8192

82-
`EXPIRE` and `TTL` operate in seconds, but there are analogous commands that operate in milliseconds. They are [PEXPIRE](https://redis.io/commands/pexpire) and [PTTL](https://redis.io/commands/pttl).
93+
`EXPIRE` and `TTL` operate in seconds, but there are analogous commands that operate in milliseconds. They are `PEXPIRE` and `PTTL`.
8394

8495
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.
8596

8697
```redis SET with time to live
8798
SET bike:1:lock_status "LOCKED" PX 1
8899
```
89100

90-
It's possible to cancel a key's timeout using the [PERSIST](https://redis.io/commands/persist) command.
101+
It's possible to cancel a key's timeout using the `PERSIST` command.
91102

92103
```redis PERSIST usage
93104
SET bike:1:lock_status "LOCKED" EX 120
94105
PERSIST bike:1:lock_status
95106
TTL bike:1:lock_status
96107
```
97108

98-
See the [SET](https://redis.io/commands/set) command manual page for more time-related and other arguments.
99-
100-
See [here](https://redis.io/commands/?group=string) for the entire set of Redis string-related commands.
109+
See [here](https://redis.io/docs/data-types/strings) for the string type reference page, and [here](https://redis.io/commands/?group=string) for the entire set of Redis string commands.

0 commit comments

Comments
 (0)