Skip to content

Commit c4e5bba

Browse files
committed
feat: add HEXPIRE docs to the redis SDKs
1 parent 608a2b3 commit c4e5bba

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

mint.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236
"pages": [
237237
"redis/sdks/ts/commands/hash/hdel",
238238
"redis/sdks/ts/commands/hash/hexists",
239+
"redis/sdks/ts/commands/hash/hexpire",
239240
"redis/sdks/ts/commands/hash/hget",
240241
"redis/sdks/ts/commands/hash/hgetall",
241242
"redis/sdks/ts/commands/hash/hincrby",
@@ -465,6 +466,7 @@
465466
"pages": [
466467
"redis/sdks/py/commands/hash/hdel",
467468
"redis/sdks/py/commands/hash/hexists",
469+
"redis/sdks/py/commands/hash/hexpire",
468470
"redis/sdks/py/commands/hash/hget",
469471
"redis/sdks/py/commands/hash/hgetall",
470472
"redis/sdks/py/commands/hash/hincrby",
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 the number of fields for which 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>

redis/sdks/ts/commands/hash/hexists.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ description: Checks if a field exists in a hash.
2424
```ts Example
2525
await redis.hset("key", "field", "value");
2626
const exists = await redis.hexists("key", "field");
27-
console.log(exists); // 1
2827

28+
console.log(exists); // 1
2929
```
3030
</RequestExample>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: HEXPIRE
3+
description: Sets an expiration time for one or more fields in a hash.
4+
---
5+
6+
## Arguments
7+
8+
<ParamField body="key" type="string" required>
9+
The key of the hash.
10+
</ParamField>
11+
12+
<ParamField body="field" type="string | string[]" required>
13+
The field or fields to set an expiration time for.
14+
</ParamField>
15+
16+
<ParamField body="ttl" type="number" required>
17+
The time-to-live (TTL) in seconds.
18+
</ParamField>
19+
20+
<ParamField body="condition" type="string" optional>
21+
Optional condition for setting the expiration:
22+
- `NX`: Set the expiration only if the field does not already have an expiration.
23+
- `XX`: Set the expiration only if the field already has an expiration.
24+
- `GT`: Set the expiration only if the new TTL is greater than the current TTL.
25+
- `LT`: Set the expiration only if the new TTL is less than the current TTL.
26+
</ParamField>
27+
28+
## Response
29+
30+
<ResponseField type="integer[]" required>
31+
A list of integers indicating the number of fields for which the expiry was successfully set.
32+
33+
- `-2` if the field does not exist in the hash or if key doesn't exist.
34+
- `0` if the expiration was not set due to the condition.
35+
- `1` if the expiration was successfully set.
36+
- `2` if called with 0 seconds/milliseconds or a past Unix time.
37+
38+
For more details, see [HEXPIRE documentation](https://redis.io/commands/hexpire).
39+
</ResponseField>
40+
41+
42+
<RequestExample>
43+
```ts Example
44+
await redis.hset("my-key", "my-field", "my-value");
45+
const expirationSet = await redis.hexpire("my-key", "my-field", 1);
46+
47+
console.log(expirationSet); // 1
48+
```
49+
</RequestExample>

0 commit comments

Comments
 (0)