Skip to content

Commit 3718c19

Browse files
authored
Add hash expiration docs to the redis SDKs (#430)
* feat: add HEXPIRE docs to the redis SDKs * fix: add hexpire to overviews * fix: add other hash commands * fix: review * fix: add links to redis commands
1 parent fd36138 commit 3718c19

23 files changed

+837
-3
lines changed

mint.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@
237237
"pages": [
238238
"redis/sdks/ts/commands/hash/hdel",
239239
"redis/sdks/ts/commands/hash/hexists",
240+
"redis/sdks/ts/commands/hash/hexpire",
241+
"redis/sdks/ts/commands/hash/hexpireat",
242+
"redis/sdks/ts/commands/hash/hexpiretime",
240243
"redis/sdks/ts/commands/hash/hget",
241244
"redis/sdks/ts/commands/hash/hgetall",
242245
"redis/sdks/ts/commands/hash/hincrby",
@@ -247,8 +250,14 @@
247250
"redis/sdks/ts/commands/hash/hrandfield",
248251
"redis/sdks/ts/commands/hash/hscan",
249252
"redis/sdks/ts/commands/hash/hset",
253+
"redis/sdks/ts/commands/hash/hpersist",
254+
"redis/sdks/ts/commands/hash/hpexpire",
255+
"redis/sdks/ts/commands/hash/hpexpireat",
256+
"redis/sdks/ts/commands/hash/hpexpiretime",
257+
"redis/sdks/ts/commands/hash/hpttl",
250258
"redis/sdks/ts/commands/hash/hsetnx",
251259
"redis/sdks/ts/commands/hash/hstrlen",
260+
"redis/sdks/ts/commands/hash/httl",
252261
"redis/sdks/ts/commands/hash/hvals"
253262
]
254263
},
@@ -468,6 +477,9 @@
468477
"pages": [
469478
"redis/sdks/py/commands/hash/hdel",
470479
"redis/sdks/py/commands/hash/hexists",
480+
"redis/sdks/py/commands/hash/hexpire",
481+
"redis/sdks/py/commands/hash/hexpireat",
482+
"redis/sdks/py/commands/hash/hexpiretime",
471483
"redis/sdks/py/commands/hash/hget",
472484
"redis/sdks/py/commands/hash/hgetall",
473485
"redis/sdks/py/commands/hash/hincrby",
@@ -478,9 +490,15 @@
478490
"redis/sdks/py/commands/hash/hrandfield",
479491
"redis/sdks/py/commands/hash/hscan",
480492
"redis/sdks/py/commands/hash/hset",
493+
"redis/sdks/py/commands/hash/hpersist",
494+
"redis/sdks/py/commands/hash/hpexpire",
495+
"redis/sdks/py/commands/hash/hpexpireat",
496+
"redis/sdks/py/commands/hash/hpexpiretime",
497+
"redis/sdks/py/commands/hash/hpttl",
481498
"redis/sdks/py/commands/hash/hmset",
482499
"redis/sdks/py/commands/hash/hsetnx",
483500
"redis/sdks/py/commands/hash/hstrlen",
501+
"redis/sdks/py/commands/hash/httl",
484502
"redis/sdks/py/commands/hash/hvals"
485503
]
486504
},
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: HEXPIRE
3+
description: Set a timeout on a hash field in seconds.
4+
---
5+
6+
## Arguments
7+
8+
<ParamField body="key" type="str" required>
9+
The key of the hash.
10+
</ParamField>
11+
12+
<ParamField body="fields" type="Union[str, List[str]]" required>
13+
The field or list of fields within the hash to set the expiry for.
14+
</ParamField>
15+
16+
<ParamField body="seconds" type="Union[int, datetime.timedelta]" required>
17+
The timeout in seconds as an integer or a `datetime.timedelta` object.
18+
</ParamField>
19+
20+
<ParamField body="nx" type="bool" optional>
21+
Set expiry only when the field has no expiry. Defaults to `False`.
22+
</ParamField>
23+
24+
<ParamField body="xx" type="bool" optional>
25+
Set expiry only when the field has an existing expiry. Defaults to `False`.
26+
</ParamField>
27+
28+
<ParamField body="gt" type="bool" optional>
29+
Set expiry only when the new expiry is greater than the current one. Defaults to `False`.
30+
</ParamField>
31+
32+
<ParamField body="lt" type="bool" optional>
33+
Set expiry only when the new expiry is less than the current one. Defaults to `False`.
34+
</ParamField>
35+
36+
## Response
37+
38+
<ResponseField type="List[int]" required>
39+
A list of integers indicating whether the expiry was successfully set.
40+
41+
- `-2` if the field does not exist in the hash or if key doesn't exist.
42+
- `0` if the expiration was not set due to the condition.
43+
- `1` if the expiration was successfully set.
44+
- `2` if called with 0 seconds/milliseconds or a past Unix time.
45+
46+
For more details, see [HEXPIRE documentation](https://redis.io/commands/hexpire).
47+
</ResponseField>
48+
49+
<RequestExample>
50+
```py Example
51+
redis.hset(hash_name, field, value)
52+
53+
assert redis.hexpire(hash_name, field, 1) == [1]
54+
```
55+
</RequestExample>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: HEXPIREAT
3+
description: Sets an expiration time for field(s) in a hash in seconds since the Unix epoch.
4+
---
5+
6+
## Arguments
7+
8+
<ParamField body="key" type="str" required>
9+
The key of the hash.
10+
</ParamField>
11+
12+
<ParamField body="fields" type="Union[str, List[str]]" required>
13+
The field or list of fields to set an expiration time for.
14+
</ParamField>
15+
16+
<ParamField body="timestamp" type="int" required>
17+
The expiration time as a Unix timestamp in seconds.
18+
</ParamField>
19+
20+
<ParamField body="nx" type="bool" optional>
21+
Set expiry only when the field has no expiry. Defaults to `False`.
22+
</ParamField>
23+
24+
<ParamField body="xx" type="bool" optional>
25+
Set expiry only when the field has an existing expiry. Defaults to `False`.
26+
</ParamField>
27+
28+
<ParamField body="gt" type="bool" optional>
29+
Set expiry only when the new expiry is greater than the current one. Defaults to `False`.
30+
</ParamField>
31+
32+
<ParamField body="lt" type="bool" optional>
33+
Set expiry only when the new expiry is less than the current one. Defaults to `False`.
34+
</ParamField>
35+
36+
## Response
37+
38+
<ResponseField type="List[int]" required>
39+
A list of integers indicating whether the expiry was successfully set.
40+
41+
- `-2` if the field does not exist in the hash or if the key doesn't exist.
42+
- `0` if the expiration was not set due to the condition.
43+
- `1` if the expiration was successfully set.
44+
- `2` if called with 0 seconds/milliseconds or a past Unix time.
45+
46+
For more details, see [HEXPIREAT documentation](https://redis.io/commands/hexpireat).
47+
</ResponseField>
48+
49+
<RequestExample>
50+
```py Example
51+
redis.hset(hash_name, field, value)
52+
53+
assert redis.hexpireat(hash_name, field, int(time.time()) + 10) == [1]
54+
```
55+
</RequestExample>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: HEXPIRETIME
3+
description: Retrieves the expiration time of field(s) in a hash in seconds.
4+
---
5+
6+
## Arguments
7+
8+
<ParamField body="key" type="str" required>
9+
The key of the hash.
10+
</ParamField>
11+
12+
<ParamField body="fields" type="Union[str, List[str]]" required>
13+
The field or list of fields to retrieve the expiration time for.
14+
</ParamField>
15+
16+
## Response
17+
18+
<ResponseField type="List[int]" required>
19+
A list of integers representing the expiration time in seconds since the Unix epoch.
20+
21+
- `-2` if the field does not exist in the hash or if the key doesn't exist.
22+
- `-1` if the field exists but has no associated expiration.
23+
24+
For more details, see [HEXPIRETIME documentation](https://redis.io/commands/hexpiretime).
25+
</ResponseField>
26+
27+
<RequestExample>
28+
```py Example
29+
redis.hset(hash_name, field, value)
30+
redis.hexpireat(hash_name, field, int(time.time()) + 10)
31+
32+
assert redis.hexpiretime(hash_name, field) == [1697059200]
33+
```
34+
</RequestExample>

redis/sdks/py/commands/hash/hkeys.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ redis.hset("myhash", values={
2424
})
2525

2626
assert redis.hkeys("myhash") == ["field1", "field2"]
27-
2827
```
2928
</RequestExample>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: HPERSIST
3+
description: Remove the expiration from one or more hash fields.
4+
---
5+
6+
## Arguments
7+
8+
<ParamField body="key" type="str" required>
9+
The key of the hash.
10+
</ParamField>
11+
12+
<ParamField body="fields" type="Union[str, List[str]]" required>
13+
The field or list of fields within the hash to remove the expiry from.
14+
</ParamField>
15+
16+
## Response
17+
18+
<ResponseField type="List[int]" required>
19+
A list of integers indicating the result for each field:
20+
21+
- `-2` if the field does not exist in the hash or if the key doesn't exist.
22+
- `-1` if the field exists but has no associated expiration set.
23+
- `1` if the expiration was successfully removed.
24+
25+
For more details, see [HPERSIST documentation](https://redis.io/commands/hpersist).
26+
</ResponseField>
27+
28+
<RequestExample>
29+
```py Example
30+
redis.hset(hash_name, field, value)
31+
redis.hpexpire(hash_name, field, 1000)
32+
33+
assert redis.hpersist(hash_name, field) == [1]
34+
```
35+
</RequestExample>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: HPEXPIRE
3+
description: Set a timeout on a hash field in milliseconds.
4+
---
5+
6+
## Arguments
7+
8+
<ParamField body="key" type="str" required>
9+
The key of the hash.
10+
</ParamField>
11+
12+
<ParamField body="fields" type="Union[str, List[str]]" required>
13+
The field or list of fields within the hash to set the expiry for.
14+
</ParamField>
15+
16+
<ParamField body="milliseconds" type="Union[int, datetime.timedelta]" required>
17+
The timeout in milliseconds as an integer or a `datetime.timedelta` object.
18+
</ParamField>
19+
20+
<ParamField body="nx" type="bool" optional>
21+
Set expiry only when the field has no expiry. Defaults to `False`.
22+
</ParamField>
23+
24+
<ParamField body="xx" type="bool" optional>
25+
Set expiry only when the field has an existing expiry. Defaults to `False`.
26+
</ParamField>
27+
28+
<ParamField body="gt" type="bool" optional>
29+
Set expiry only when the new expiry is greater than the current one. Defaults to `False`.
30+
</ParamField>
31+
32+
<ParamField body="lt" type="bool" optional>
33+
Set expiry only when the new expiry is less than the current one. Defaults to `False`.
34+
</ParamField>
35+
36+
## Response
37+
38+
<ResponseField type="List[int]" required>
39+
A list of integers indicating whether the expiry was successfully set.
40+
41+
- `-2` if the field does not exist in the hash or if key doesn't exist.
42+
- `0` if the expiration was not set due to the condition.
43+
- `1` if the expiration was successfully set.
44+
- `2` if called with 0 seconds/milliseconds or a past Unix time.
45+
46+
For more details, see [HPEXPIRE documentation](https://redis.io/commands/hpexpire).
47+
</ResponseField>
48+
49+
<RequestExample>
50+
```py Example
51+
redis.hset(hash_name, field, value)
52+
53+
assert redis.hpexpire(hash_name, field, 1000) == [1]
54+
```
55+
</RequestExample>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: HPEXPIREAT
3+
description: Sets an expiration time for field(s) in a hash in milliseconds since the Unix epoch.
4+
---
5+
6+
## Arguments
7+
8+
<ParamField body="key" type="str" required>
9+
The key of the hash.
10+
</ParamField>
11+
12+
<ParamField body="fields" type="Union[str, List[str]]" required>
13+
The field or list of fields to set an expiration time for.
14+
</ParamField>
15+
16+
<ParamField body="timestamp" type="int" required>
17+
The expiration time as a Unix timestamp in milliseconds.
18+
</ParamField>
19+
20+
<ParamField body="nx" type="bool" optional>
21+
Set expiry only when the field has no expiry. Defaults to `False`.
22+
</ParamField>
23+
24+
<ParamField body="xx" type="bool" optional>
25+
Set expiry only when the field has an existing expiry. Defaults to `False`.
26+
</ParamField>
27+
28+
<ParamField body="gt" type="bool" optional>
29+
Set expiry only when the new expiry is greater than the current one. Defaults to `False`.
30+
</ParamField>
31+
32+
<ParamField body="lt" type="bool" optional>
33+
Set expiry only when the new expiry is less than the current one. Defaults to `False`.
34+
</ParamField>
35+
36+
## Response
37+
38+
<ResponseField type="List[int]" required>
39+
A list of integers indicating whether the expiry was successfully set.
40+
41+
- `-2` if the field does not exist in the hash or if the key doesn't exist.
42+
- `0` if the expiration was not set due to the condition.
43+
- `1` if the expiration was successfully set.
44+
- `2` if called with 0 seconds/milliseconds or a past Unix time.
45+
46+
For more details, see [HPEXPIREAT documentation](https://redis.io/commands/hpexpireat).
47+
</ResponseField>
48+
49+
<RequestExample>
50+
```py Example
51+
redis.hset(hash_name, field, value)
52+
53+
assert redis.hpexpireat(hash_name, field, int(time.time() * 1000) + 1000) == [1]
54+
```
55+
</RequestExample>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: HPEXPIRETIME
3+
description: Retrieves the expiration time of a field in a hash in milliseconds.
4+
---
5+
6+
## Arguments
7+
8+
<ParamField body="key" type="str" required>
9+
The key of the hash.
10+
</ParamField>
11+
12+
<ParamField body="fields" type="Union[str, List[str]]" required>
13+
The field or list of fields to retrieve the expiration time for.
14+
</ParamField>
15+
16+
## Response
17+
18+
<ResponseField type="List[int]" required>
19+
A list of integers representing the expiration time in milliseconds since the Unix epoch.
20+
21+
- `-2` if the field does not exist in the hash or if the key doesn't exist.
22+
- `-1` if the field exists but has no associated expiration.
23+
24+
For more details, see [HPEXPIRETIME documentation](https://redis.io/commands/hpexpiretime).
25+
</ResponseField>
26+
27+
<RequestExample>
28+
```py Example
29+
redis.hset(hash_name, field, value)
30+
redis.hpexpireat(hash_name, field, int(time.time() * 1000) + 1000)
31+
32+
assert redis.hpexpiretime(hash_name, field) == [1697059200000]
33+
```
34+
</RequestExample>

0 commit comments

Comments
 (0)