@@ -10,7 +10,7 @@ import PageTitle from '@site/src/components/PageTitle';
10
10
11
11
## Syntax
12
12
13
- EXPIRE key seconds
13
+ EXPIRE key seconds [NX | XX | GT | LT]
14
14
15
15
** Time complexity:** O(1)
16
16
@@ -49,13 +49,20 @@ will be `del`, not `expired`).
49
49
[ del ] : ./del.md
50
50
[ ntf ] : https://redis.io/topics/notifications
51
51
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
53
60
54
61
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.
57
64
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.
59
66
60
67
## Return
61
68
@@ -79,12 +86,12 @@ dragonfly> TTL mykey
79
86
(integer) -1
80
87
```
81
88
82
- ## Pattern: Navigation session
89
+ ## Pattern: Navigation Session
83
90
84
91
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
86
93
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 **
88
95
of your user, that may contain interesting information about what kind of
89
96
products he or she is looking for currently, so that you can recommend related
90
97
products.
@@ -100,54 +107,53 @@ EXEC
100
107
```
101
108
102
109
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 .
105
112
106
- This pattern is easily modified to use counters using ` INCR ` instead of lists
107
- using ` RPUSH ` .
113
+ ---
108
114
109
- # Appendix: Dragonfly expires
115
+ ## Appendix: Dragonfly Expiries
110
116
111
- ## Keys with an expire
117
+ ### Keys with an Expiry
112
118
113
119
Normally Dragonfly keys are created without an associated time to live.
114
120
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.
116
122
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,
118
124
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.
121
127
122
128
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).
124
130
125
- ## Expire accuracy
131
+ ### Expiry Accuracy
126
132
127
- Dragonfly expire accuracy is in order of milliseconds.
133
+ Dragonfly expiry accuracy is in order of milliseconds.
128
134
129
- ## How Dragonfly expires keys
135
+ ### How Dragonfly Expires Keys
130
136
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.
132
138
133
139
A key is passively expired simply when some client tries to access it, and the
134
140
key is found to be timed out.
135
141
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
137
143
accessed again.
138
144
These keys should be expired anyway, so periodically Dragonfly tests a few keys at
139
145
random among keys with an expire set.
140
146
All the keys that are already expired are deleted from the keyspace.
141
147
142
- ## How expires are handled in the replication link
148
+ ### How Expiries Are Handled in the Replication Link
143
149
144
150
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.
146
152
This way the expiration process is centralized in the master instance, and there
147
153
is no chance of consistency errors.
148
154
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
150
156
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,
153
159
fully acting as a master.
0 commit comments