Skip to content

Commit 37188d7

Browse files
abhijatNiennienzz
andauthored
feat: Add flags and examples for commands found missing in fixit (#440)
* feat: Add flags for pexpire command * feat: Add docs for new flags in pexpireat command * feat: Add compat-entry for slowlog help * feat: Add docs for pexpiretime and compat-matrix * minor: styling for PEXPIRE & PEXPIREAT; add options for EXPIRE & EXPIREAT Signed-off-by: Abhijat Malviya <[email protected]> Co-authored-by: Joe Zhou <[email protected]>
1 parent 081ac45 commit 37188d7

File tree

6 files changed

+115
-32
lines changed

6 files changed

+115
-32
lines changed

docs/command-reference/compatibility.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ sidebar_position: 0
5555
| | <span class="command">PERSIST</span> | <span class="support supported">Fully supported</span> |
5656
| | <span class="command">PEXPIRE</span> | <span class="support supported">Fully supported</span> |
5757
| | <span class="command">PEXPIREAT</span> | <span class="support supported">Fully supported</span> |
58-
| | <span class="command">PEXPIRETIME</span> | <span class="support unsupported">Unsupported</span> |
58+
| | <span class="command">PEXPIRETIME</span> | <span class="support supported">Fully supported</span> |
5959
| | <span class="command">PTTL</span> | <span class="support supported">Fully supported</span> |
6060
| | <span class="command">RANDOMKEY</span> | <span class="support unsupported">Unsupported</span> |
6161
| | <span class="command">RENAME</span> | <span class="support supported">Fully supported</span> |
@@ -193,6 +193,7 @@ sidebar_position: 0
193193
| | <span class="command">SHUTDOWN</span> | <span class="support supported">Fully supported</span> |
194194
| | <span class="command">SLAVEOF</span> | <span class="support supported">Fully supported</span> |
195195
| | <span class="command">SLOWLOG GET</span> | <span class="support supported">Fully supported</span> |
196+
| | <span class="command">SLOWLOG HELP</span> | <span class="support supported">Fully supported</span> |
196197
| | <span class="command">SLOWLOG LEN</span> | <span class="support supported">Fully supported</span> |
197198
| | <span class="command">SLOWLOG RESET</span> | <span class="support supported">Fully supported</span> |
198199
| | <span class="command">SWAPDB</span> | <span class="support unsupported">Unsupported</span> |

docs/command-reference/generic/expire.md

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

1111
## Syntax
1212

13-
EXPIRE key seconds
13+
EXPIRE key seconds [NX | XX | GT | LT]
1414

1515
**Time complexity:** O(1)
1616

@@ -49,13 +49,20 @@ will be `del`, not `expired`).
4949
[del]: ./del.md
5050
[ntf]: https://redis.io/topics/notifications
5151

52-
## Refreshing expires
52+
## Options
53+
54+
- `NX`: Expiry will only be set if the key has no expiry.
55+
- `XX`: Expiry will only be set if the key has an existing expiry.
56+
- `GT`: Expiry will only be set if the new expiry is greater than current one.
57+
- `LT`: Expiry will only be set if the new expiry is less than current one.
58+
59+
## Refreshing Expiries
5360

5461
It is possible to call `EXPIRE` using as argument a key that already has an
55-
existing expire set.
56-
In this case the time to live of a key is _updated_ to the new value.
62+
existing expiry set.
63+
In this case the time to live of a key is **updated** to the new value.
5764
There are many useful applications for this, an example is documented in the
58-
_Navigation session_ pattern section below.
65+
**Navigation Session** pattern section below.
5966

6067
## Return
6168

@@ -79,12 +86,12 @@ dragonfly> TTL mykey
7986
(integer) -1
8087
```
8188

82-
## Pattern: Navigation session
89+
## Pattern: Navigation Session
8390

8491
Imagine you have a web service and you are interested in the latest N pages
85-
_recently_ visited by your users, such that each adjacent page view was not
92+
**recently** visited by your users, such that each adjacent page view was not
8693
performed more than 60 seconds after the previous.
87-
Conceptually you may consider this set of page views as a _Navigation session_
94+
Conceptually you may consider this set of page views as a **navigation session**
8895
of your user, that may contain interesting information about what kind of
8996
products he or she is looking for currently, so that you can recommend related
9097
products.
@@ -100,54 +107,53 @@ EXEC
100107
```
101108

102109
If the user will be idle more than 60 seconds, the key will be deleted and only
103-
subsequent page views that have less than 60 seconds of difference will be
104-
recorded.
110+
subsequent page views that have less than 60 seconds of difference will be recorded.
111+
This pattern can also be easily modified to use counters (i.e., `INCR`) instead of lists.
105112

106-
This pattern is easily modified to use counters using `INCR` instead of lists
107-
using `RPUSH`.
113+
---
108114

109-
# Appendix: Dragonfly expires
115+
## Appendix: Dragonfly Expiries
110116

111-
## Keys with an expire
117+
### Keys with an Expiry
112118

113119
Normally Dragonfly keys are created without an associated time to live.
114120
The key will simply live forever, unless it is removed by the user in an
115-
explicit way, for instance using the `DEL` command.
121+
explicit way, for instance, using the `DEL` command.
116122

117-
The `EXPIRE` family of commands is able to associate an expire to a given key,
123+
The `EXPIRE` family of commands is able to associate an expiry to a given key,
118124
at the cost of some additional memory used by the key.
119-
When a key has an expire set, Dragonfly will make sure to remove the key when the
120-
specified amount of time elapsed.
125+
When a key has an expiry set, Dragonfly will make sure to remove the key when the
126+
specified amount of time has elapsed.
121127

122128
The key time to live can be updated or entirely removed using the `EXPIRE` and
123-
`PERSIST` command (or other strictly related commands).
129+
`PERSIST` commands (or other strictly related commands).
124130

125-
## Expire accuracy
131+
### Expiry Accuracy
126132

127-
Dragonfly expire accuracy is in order of milliseconds.
133+
Dragonfly expiry accuracy is in order of milliseconds.
128134

129-
## How Dragonfly expires keys
135+
### How Dragonfly Expires Keys
130136

131-
Dragonfly keys are expired in two ways: a passive way, and an active way.
137+
Dragonfly keys expire in two ways: a passive way and an active way.
132138

133139
A key is passively expired simply when some client tries to access it, and the
134140
key is found to be timed out.
135141

136-
Of course this is not enough as there are expired keys that will never be
142+
Of course this is not enough, as there are expired keys that will never be
137143
accessed again.
138144
These keys should be expired anyway, so periodically Dragonfly tests a few keys at
139145
random among keys with an expire set.
140146
All the keys that are already expired are deleted from the keyspace.
141147

142-
## How expires are handled in the replication link
148+
### How Expiries Are Handled in the Replication Link
143149

144150
In order to obtain a correct behavior without sacrificing consistency, when a
145-
key expires, a `DEL` operation is sent to all the attached replicas nodes.
151+
key expires, a `DEL` operation is sent to all the attached replica nodes.
146152
This way the expiration process is centralized in the master instance, and there
147153
is no chance of consistency errors.
148154

149-
However while the replicas connected to a master will not expire keys
155+
However, while the replicas connected to a master will not expire keys
150156
independently (but will wait for the `DEL` coming from the master), they'll
151-
still take the full state of the expires existing in the dataset, so when a
152-
replica is elected to master it will be able to expire the keys independently,
157+
still take the full state of the expiries existing in the dataset, so when a
158+
replica is elected to master, it will be able to expire the keys independently,
153159
fully acting as a master.

docs/command-reference/generic/expireat.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ timestamp in the past will delete the key immediately.
2626
Please for the specific semantics of the command refer to the documentation of
2727
`EXPIRE`.
2828

29+
## Options
30+
31+
- `NX`: Expiry will only be set if the key has no expiry.
32+
- `XX`: Expiry will only be set if the key has an existing expiry.
33+
- `GT`: Expiry will only be set if the new expiry is greater than current one.
34+
- `LT`: Expiry will only be set if the new expiry is less than current one.
35+
2936
## Return
3037

3138
[Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec/#integers), specifically:

docs/command-reference/generic/pexpire.md

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

1111
## Syntax
1212

13-
PEXPIRE key milliseconds
13+
PEXPIRE key milliseconds [NX | XX | GT | LT]
1414

1515
**Time complexity:** O(1)
1616

@@ -19,6 +19,13 @@ import PageTitle from '@site/src/components/PageTitle';
1919
This command works exactly like `EXPIRE` but the time to live of the key is
2020
specified in milliseconds instead of seconds.
2121

22+
## Options
23+
24+
- `NX`: Expiry will only be set if the key has no expiry.
25+
- `XX`: Expiry will only be set if the key has an existing expiry.
26+
- `GT`: Expiry will only be set if the new expiry is greater than current one.
27+
- `LT`: Expiry will only be set if the new expiry is less than current one.
28+
2229
## Return
2330

2431
[Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec/#integers), specifically:
@@ -37,4 +44,16 @@ dragonfly> TTL mykey
3744
(integer) 2
3845
dragonfly> PTTL mykey
3946
(integer) 1500
47+
dragonfly> PEXPIRE mykey 1 GT
48+
(integer) 0
49+
dragonfly> PTTL mykey
50+
(integer) 1500
51+
dragonfly> PEXPIRE mykey 30000 LT
52+
(integer) 0
53+
dragonfly> PTTL mykey
54+
(integer) 1500
55+
dragonfly> PEXPIRE mykey 111 NX
56+
(integer) 0
57+
dragonfly> PTTL mykey
58+
(integer) 1500
4059
```

docs/command-reference/generic/pexpireat.md

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

1111
## Syntax
1212

13-
PEXPIREAT key unix-time-milliseconds
13+
PEXPIREAT key unix-time-milliseconds [NX | XX | GT | LT]
1414

1515
**Time complexity:** O(1)
1616

@@ -19,6 +19,13 @@ import PageTitle from '@site/src/components/PageTitle';
1919
`PEXPIREAT` has the same effect and semantic as `EXPIREAT`, but the Unix time at
2020
which the key will expire is specified in milliseconds instead of seconds.
2121

22+
## Options
23+
24+
- `NX`: Expiry will only be set if the key has no expiry.
25+
- `XX`: Expiry will only be set if the key has an existing expiry.
26+
- `GT`: Expiry will only be set if the new expiry is greater than current one.
27+
- `LT`: Expiry will only be set if the new expiry is less than current one.
28+
2229
## Return
2330

2431
[Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec/#integers), specifically:
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
description: "PEXPIRETIME returns absolute unix expiry of a key in milliseconds."
3+
---
4+
5+
import PageTitle from '@site/src/components/PageTitle';
6+
7+
# PEXPIRETIME
8+
9+
<PageTitle title="Redis PEXPIRETIME Command (Documentation) | Dragonfly" />
10+
11+
## Syntax
12+
13+
PEXPIRETIME key
14+
15+
**Time complexity:** O(1)
16+
17+
**ACL categories:** @keyspace, @write, @fast
18+
19+
This command works exactly like `EXPIRETIME` but the absolute unix expiration timestamp of the key is
20+
returned in milliseconds instead of seconds.
21+
22+
## Return
23+
24+
[Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec/#integers), specifically:
25+
26+
- The expiration unix timestamp, in milliseconds
27+
- `-1` if the key exists but has no expiration time.
28+
- `-2` if the key does not exist.
29+
30+
## Examples
31+
32+
```shell
33+
dragonfly> SET mykey "Hello"
34+
OK
35+
dragonfly> PEXPIRETIME mykey
36+
(integer) -1
37+
dragonfly> PEXPIRETIME missing
38+
(integer) -2
39+
dragonfly> EXPIRE mykey 100
40+
(integer) 1
41+
dragonfly> PEXPIRETIME mykey
42+
(integer) 1755753267438
43+
```

0 commit comments

Comments
 (0)