From 7f5ec3324e7f5dd255882cb4cd1843e0bc7f564f Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Tue, 10 Nov 2026 10:48:33 +0000 Subject: [PATCH] DOC-7293 Add a Jedis set member expiration example to the sets page Adds a `member_expiration` step to the `sets_tutorial` Jedis example (SADDEX with SAddExParams, SADD, STTL) and wraps the matching redis-cli block in the Member expiration section of sets.md in a clients-example shortcode, restricted to Java-Sync with lang_filter. Parked: the Jedis set member expiration API (#4828) is merged on master but not in any release (latest is v8.1.0-beta2, tagged before the merge). The example compiled against jedis master c701a365 built locally. It has NOT been run: no Redis 8.12 server was available (Docker not running; local redis-server is 7.2.7), so the `// >>>` values are taken from the server-authored redis-cli block on the same page, not from a run. On unpark: re-run against the released Jedis and a real 8.12 server; the harness's pinned Jedis (run.sh sets_tutorial:jedis) will not compile this step until it is bumped. Learned: - Other clients are deliberately omitted via lang_filter, because a step missing from a client renders the whole file for it. Add each client to the allowlist only when its set member expiration support has shipped. - The existing step `srem` prints res18 after assigning res19; left alone. - examples/ is gitignored build output, so only local_examples/ changes. Co-Authored-By: Claude Sonnet 5.5 --- content/develop/data-types/sets.md | 4 ++-- .../tmp/datatypes/sets/SetsExample.java | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/content/develop/data-types/sets.md b/content/develop/data-types/sets.md index ccdb286109..e67566d0a5 100644 --- a/content/develop/data-types/sets.md +++ b/content/develop/data-types/sets.md @@ -223,7 +223,7 @@ Because the members expire, each example recreates the `bikes:reserved` set firs Add two members with a TTL of 15 minutes, add a third member with no expiration, and then retrieve the remaining TTL of each member: -```redis +{{< clients-example set="sets_tutorial" step="member_expiration" lang_filter="Java-Sync" description="Member expiration: Add set members with a TTL using SADDEX, then read each member's remaining TTL with STTL" difficulty="intermediate" buildsUpon="sadd" >}} > DEL bikes:reserved (integer) 0 > SADDEX bikes:reserved EX 900 MEMBERS 2 bike:1 bike:2 @@ -234,7 +234,7 @@ Add two members with a TTL of 15 minutes, add a third member with no expiration, 1) (integer) 900 2) (integer) 900 3) (integer) -1 -``` +{{< /clients-example >}} Set a member's TTL in milliseconds, retrieve the remaining TTL in milliseconds, and then remove the expiration: diff --git a/local_examples/tmp/datatypes/sets/SetsExample.java b/local_examples/tmp/datatypes/sets/SetsExample.java index ecc08111c4..3cf34f50da 100644 --- a/local_examples/tmp/datatypes/sets/SetsExample.java +++ b/local_examples/tmp/datatypes/sets/SetsExample.java @@ -10,6 +10,7 @@ // REMOVE_END // HIDE_START import redis.clients.jedis.RedisClient; +import redis.clients.jedis.params.SAddExParams; import java.util.List; import java.util.Set; @@ -190,6 +191,26 @@ public void run() { assertEquals(1,res19); // REMOVE_END + // STEP_START member_expiration + jedis.del("bikes:reserved"); + + long res23 = jedis.saddex("bikes:reserved", SAddExParams.sAddExParams().ex(900), "bike:1", "bike:2"); + System.out.println(res23); // >>> 1 + + long res24 = jedis.sadd("bikes:reserved", "bike:3"); + System.out.println(res24); // >>> 1 + + List res25 = jedis.sttl("bikes:reserved", "bike:1", "bike:2", "bike:3"); + System.out.println(res25); // >>> [900, 900, -1] + // STEP_END + + // REMOVE_START + assertEquals(1, res23); + assertEquals(1, res24); + assertEquals(List.of(900L, 900L, -1L), res25); + jedis.del("bikes:reserved"); + // REMOVE_END + // HIDE_START jedis.close(); // HIDE_END