Skip to content

Commit 6067ef2

Browse files
Docs Originality Update - Batch #7 (#293)
* 13 more sorted set docs - make original * dragonfly prompt * adjust ZRANK * adjust ZREM * adjust ZREMRANGEBYLEX * adjust ZREMRANGEBYRANK * adjust ZREMRANGEBYSCORE * adjust ZREVRANGE & ZREVRANGEBYLEX * adjust ZREVRANGEBYSCORE * adjust ZREVRANK * adjust ZSCAN * adjust ZSCORE * adjust ZUNION * adjust ZUNIONSTORE --------- Co-authored-by: Joe Zhou <[email protected]>
1 parent 45b1c8f commit 6067ef2

22 files changed

+1253
-373
lines changed

docs/command-reference/sorted-sets/bzpopmax.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Pop the highest score element from a sorted set:
4848
```shell
4949
dragonfly$> ZADD myzset 1 "item1" 2 "item2" 3 "item3"
5050
(integer) 3
51+
5152
dragonfly$> BZPOPMAX myzset 0
5253
1) "myzset"
5354
2) "item3"
@@ -61,12 +62,15 @@ If the sorted set is empty, `BZPOPMAX` will wait for new elements or until the t
6162
```shell
6263
dragonfly$> ZADD myzset 1 "item1" 2 "item2"
6364
(integer) 2
65+
6466
dragonfly$> ZPOPMAX myzset
6567
1) "item2"
6668
2) "2"
69+
6770
dragonfly$> ZPOPMAX myzset
6871
1) "item1"
6972
2) "1"
73+
7074
dragonfly$> BZPOPMAX myzset 5
7175
(nil) # No elements in the sorted set, waited for 5 seconds and then returned nil.
7276
```
@@ -79,8 +83,10 @@ The command will act on the first non-empty set encountered:
7983
```shell
8084
dragonfly$> ZADD zset1 1 "a" 2 "b"
8185
(integer) 2
86+
8287
dragonfly$> ZADD zset2 1 "x" 3 "y"
8388
(integer) 2
89+
8490
dragonfly$> BZPOPMAX zset1 zset2 0
8591
1) "zset1" # Even though 'zset2' has a higher score, 'zset1' is popped first because it was specified first.
8692
2) "b"

docs/command-reference/sorted-sets/bzpopmin.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Pop the element with the lowest score from a single sorted set with a 5-second t
4949
```shell
5050
dragonfly$> ZADD myzset 1 "task1" 2 "task2" 3 "task3"
5151
(integer) 3
52+
5253
dragonfly$> BZPOPMIN myzset 5
5354
1) "myzset"
5455
2) "task1"
@@ -63,8 +64,10 @@ The command will act on the first non-empty set encountered:
6364
```shell
6465
dragonfly$> ZADD zset1 1 "a" 2 "b"
6566
(integer) 2
67+
6668
dragonfly$> ZADD zset2 3 "x" 4 "y"
6769
(integer) 2
70+
6871
dragonfly$> BZPOPMIN zset1 zset2 0
6972
1) "zset1"
7073
2) "a"
@@ -88,6 +91,7 @@ Use `BZPOPMIN` to fetch the highest-priority task (the one with the lowest score
8891
```shell
8992
dragonfly$> ZADD task_queue 10 "low_priority_task" 5 "medium_priority_task" 1 "high_priority_task"
9093
(integer) 3
94+
9195
dragonfly$> BZPOPMIN task_queue 0
9296
1) "task_queue"
9397
2) "high_priority_task"

docs/command-reference/sorted-sets/zcard.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ To get the number of members in a sorted set:
4040
```shell
4141
dragonfly$> ZADD myzset 1 "member1" 2 "member2" 3 "member3"
4242
(integer) 3
43+
4344
dragonfly$> ZCARD myzset
4445
(integer) 3
4546
```
@@ -60,6 +61,7 @@ Suppose you are building a leaderboard and need to know how many total players a
6061
```shell
6162
dragonfly$> ZADD leaderboard 100 "player1" 150 "player2" 200 "player3"
6263
(integer) 3
64+
6365
dragonfly$> ZCARD leaderboard
6466
(integer) 3
6567
```

docs/command-reference/sorted-sets/zcount.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ dragonfly$> ZCOUNT myzset -inf +inf
110110
111111
If the key does not exist, `ZCOUNT` will return `0`, meaning there are no members to count.
112112
113-
### Whats the difference between `ZCOUNT` and `ZRANGE`?
113+
### What's the difference between `ZCOUNT` and `ZRANGE`?
114114
115115
While `ZCOUNT` returns the number of elements in a score range, [`ZRANGE`](zrange.md) returns the elements themselves.
116116
If you only need the count, `ZCOUNT` is more efficient.

docs/command-reference/sorted-sets/zdiff.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ Return the members found in the first sorted set but not in the second:
4242
```shell
4343
dragonfly$> ZADD myzset1 1 "one" 2 "two" 3 "three"
4444
(integer) 3
45+
4546
dragonfly$> ZADD myzset2 2 "two" 4 "four"
4647
(integer) 2
48+
4749
dragonfly$> ZDIFF 2 myzset1 myzset2
4850
1) "one"
4951
2) "three"
@@ -58,8 +60,10 @@ Return both the members and their scores for the difference between two sets:
5860
```shell
5961
dragonfly$> ZADD myzset1 1 "one" 2 "two" 3 "three"
6062
(integer) 3
63+
6164
dragonfly$> ZADD myzset2 2 "two" 4 "four"
6265
(integer) 2
66+
6367
dragonfly$> ZDIFF 2 myzset1 myzset2 WITHSCORES
6468
1) "one"
6569
2) "1"
@@ -74,10 +78,13 @@ Find elements present in the first sorted set but missing in the other two sorte
7478
```shell
7579
dragonfly$> ZADD myzset1 1 "one" 2 "two" 3 "three" 4 "four"
7680
(integer) 4
81+
7782
dragonfly$> ZADD myzset2 3 "three" 4 "four"
7883
(integer) 2
84+
7985
dragonfly$> ZADD myzset3 1 "one" 5 "five"
8086
(integer) 2
87+
8188
dragonfly$> ZDIFF 3 myzset1 myzset2 myzset3
8289
1) "two"
8390
```

docs/command-reference/sorted-sets/zinterstore.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ Intersect two sorted sets and store the result in a new set:
4949
```shell
5050
dragonfly$> ZADD zset1 1 a 2 b 3 c
5151
(integer) 3
52+
5253
dragonfly$> ZADD zset2 2 a 3 b 1 d
5354
(integer) 3
55+
5456
dragonfly$> ZINTERSTORE out 2 zset1 zset2
5557
(integer) 2
58+
5659
dragonfly$> ZRANGE out 0 -1 WITHSCORES
5760
1) "a"
5861
2) "3" # Score is 1 + 2 = 3
@@ -67,10 +70,13 @@ Apply weights to each sorted set before calculating the intersection:
6770
```shell
6871
dragonfly$> ZADD zset1 1 a 2 b
6972
(integer) 2
73+
7074
dragonfly$> ZADD zset2 2 a 3 b
7175
(integer) 2
76+
7277
dragonfly$> ZINTERSTORE out 2 zset1 zset2 WEIGHTS 2 3
7378
(integer) 2
79+
7480
dragonfly$> ZRANGE out 0 -1 WITHSCORES
7581
1) "a"
7682
2) "8" # Score: (1 * 2) + (2 * 3) = 8
@@ -86,10 +92,13 @@ Change the default aggregation method to `MIN` or `MAX`:
8692
# Using MIN aggregation
8793
dragonfly$> ZADD zset1 1 a 5 b
8894
(integer) 2
95+
8996
dragonfly$> ZADD zset2 3 a 2 b
9097
(integer) 2
98+
9199
dragonfly$> ZINTERSTORE out 2 zset1 zset2 AGGREGATE MIN
92100
(integer) 2
101+
93102
dragonfly$> ZRANGE out 0 -1 WITHSCORES
94103
1) "a"
95104
2) "1" # Minimum score of 'a'
@@ -99,6 +108,7 @@ dragonfly$> ZRANGE out 0 -1 WITHSCORES
99108
# Using MAX aggregation
100109
dragonfly$> ZINTERSTORE out 2 zset1 zset2 AGGREGATE MAX
101110
(integer) 2
111+
102112
dragonfly$> ZRANGE out 0 -1 WITHSCORES
103113
1) "a"
104114
2) "3" # Maximum score of 'a'

docs/command-reference/sorted-sets/zlexcount.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Count the number of elements in a lexicographical range in a sorted set:
4545
```shell
4646
dragonfly$> ZADD myset 0 a 0 b 0 c 0 d 0 e
4747
(integer) 5
48+
4849
dragonfly$> ZLEXCOUNT myset [b [d
4950
(integer) 3
5051
```
@@ -58,6 +59,7 @@ Specify an exclusive upper range limit in a lexicographical query:
5859
```shell
5960
dragonfly$> ZADD myset 0 a 0 b 0 c 0 d 0 e
6061
(integer) 5
62+
6163
dragonfly$> ZLEXCOUNT myset [b (d
6264
(integer) 2
6365
```
@@ -71,6 +73,7 @@ To count all elements in the sorted set, use `-` and `+` as argument values deno
7173
```shell
7274
dragonfly$> ZADD myset 0 a 0 b 0 c 0 d 0 e
7375
(integer) 5
76+
7477
dragonfly$> ZLEXCOUNT myset - +
7578
(integer) 5
7679
```

docs/command-reference/sorted-sets/zrange.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import PageTitle from '@site/src/components/PageTitle';
1010

1111
## Introduction
1212

13-
In Dragonfly, as well as in Redis and Valkey, the `ZRANGE` command is used to retrieve a range of elements from a sorted set, sorted by their score in ascending order (lowest to highest).
13+
In Dragonfly, as well as in Redis and Valkey, the `ZRANGE` command is used to retrieve a range of elements from a sorted set, **sorted by their score in ascending order (lowest to highest)**.
1414
The `ZRANGE` command is highly useful when you are dealing with ordered data and need to fetch items within specific ranges of ranks or support paginated retrieval.
1515

1616
## Syntax
@@ -67,6 +67,7 @@ Retrieve a range of elements from a sorted set:
6767
```shell
6868
dragonfly$> ZADD myzset 1 "apple" 2 "banana" 3 "cherry"
6969
(integer) 3
70+
7071
dragonfly$> ZRANGE myzset 0 -1
7172
1) "apple"
7273
2) "banana"
@@ -78,6 +79,9 @@ dragonfly$> ZRANGE myzset 0 -1
7879
Get the elements and their associated scores from the sorted set `myzset`.
7980

8081
```shell
82+
dragonfly$> ZADD myzset 1 "apple" 2 "banana" 3 "cherry"
83+
(integer) 3
84+
8185
dragonfly$> ZRANGE myzset 0 -1 WITHSCORES
8286
1) "apple"
8387
2) "1"
@@ -92,6 +96,9 @@ dragonfly$> ZRANGE myzset 0 -1 WITHSCORES
9296
Get only the elements between the 1st and 2nd positions (indices 0-based):
9397

9498
```shell
99+
dragonfly$> ZADD myzset 1 "apple" 2 "banana" 3 "cherry"
100+
(integer) 3
101+
95102
dragonfly$> ZRANGE myzset 1 2
96103
1) "banana"
97104
2) "cherry"
@@ -102,6 +109,9 @@ dragonfly$> ZRANGE myzset 1 2
102109
Retrieve the last two elements from the sorted set:
103110

104111
```shell
112+
dragonfly$> ZADD myzset 1 "apple" 2 "banana" 3 "cherry"
113+
(integer) 3
114+
105115
dragonfly$> ZRANGE myzset -2 -1
106116
1) "banana"
107117
2) "cherry"

docs/command-reference/sorted-sets/zrangebylex.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ZRANGEBYLEX key min max [LIMIT offset count]
2929
- `key`: The key of the sorted set where the range query is performed.
3030
- `min` and `max`:
3131
- The minimum and maximum lexicographical values to filter the members.
32-
- Valid `start` and `stop` values must start with `(` or `[` to indicate exclusive or inclusive bounds respectively.
32+
- Valid `min` and `max` values must start with `(` or `[` to indicate exclusive or inclusive bounds respectively.
3333
- The `+` and `-` special values can be used to specify positive and negative infinity strings, respectively.
3434
- `LIMIT offset count` (optional): If specified, the command returns a subset of the elements within the specified range.
3535
- `offset`: The starting index of the subset (zero-based).

0 commit comments

Comments
 (0)