Skip to content

Commit 44c2df6

Browse files
authored
docs(example): add example for setting TTL to "HSET Field" (#2027)
* Example for setting TTL to "HSET Field" would make sense to have an example here. * docs(example): add better httl examples
1 parent fb082d6 commit 44c2df6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

examples/ttl.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ async function main() {
2525

2626
await redis.persist("foo"); // Remove the existing timeout on key "foo"
2727
console.log(await redis.ttl("foo")); // -1
28+
29+
await redis.hset("hfoo", "hbar", "hfoobar");
30+
// hexpire is available since Redis 7.4.0
31+
await redis.hexpire("hfoo", 20, "FIELDS", 1, "hbar"); // Add TTL to hset field
32+
console.log(await redis.call("httl", "hfoo", "FIELDS", "1", "hbar")); // [ 20 ]
33+
34+
await redis.hpexpire("hfoo", 10 * 1000, "FIELDS", 1, "hbar"); // unit is millisecond for hpexpire
35+
console.log(await redis.call("httl", "hfoo", "FIELDS", "1", "hbar")); // [ 10 ]
2836
}
2937

3038
main();

0 commit comments

Comments
 (0)