From f8c81ea5b4afe1810ca9621bd166b6281569c151 Mon Sep 17 00:00:00 2001 From: "David W. Dougherty" Date: Tue, 26 Aug 2025 08:51:05 -0700 Subject: [PATCH 1/4] DEV: add TCEs to EXISTS command --- content/commands/exists.md | 10 + .../NRedisStack/CmdsGenericExample.cs | 156 +++++++++++ .../new_tces/go-redis/cmds_generic_test.go | 262 ++++++++++++++++++ .../new_tces/jedis/CmdsGenericExample.java | 94 +++++++ .../CmdsGeneric-lettuce-async-Example.java | 127 +++++++++ .../CmdsGeneric-lettuce-reactive-Example.java | 109 ++++++++ .../new_tces/node-redis/cmds_generic.js | 186 +++++++++++++ .../new_tces/predis/CmdsGenericExample.php | 74 +++++ .../new_tces/redis-py/cmds_generic.py | 214 ++++++++++++++ 9 files changed, 1232 insertions(+) create mode 100644 local_examples/new_tces/NRedisStack/CmdsGenericExample.cs create mode 100644 local_examples/new_tces/go-redis/cmds_generic_test.go create mode 100644 local_examples/new_tces/jedis/CmdsGenericExample.java create mode 100644 local_examples/new_tces/lettuce/CmdsGeneric-lettuce-async-Example.java create mode 100644 local_examples/new_tces/lettuce/CmdsGeneric-lettuce-reactive-Example.java create mode 100644 local_examples/new_tces/node-redis/cmds_generic.js create mode 100644 local_examples/new_tces/predis/CmdsGenericExample.php create mode 100644 local_examples/new_tces/redis-py/cmds_generic.py diff --git a/content/commands/exists.md b/content/commands/exists.md index a1faf80376..87695ca2ff 100644 --- a/content/commands/exists.md +++ b/content/commands/exists.md @@ -58,6 +58,16 @@ The user should be aware that if the same existing key is mentioned in the argum ## Examples +{{< clients-example set="cmds_generic" step="exists" >}} +SET key1 "Hello" +EXISTS key1 +EXISTS nosuchkey +SET key2 "World" +EXISTS key1 key2 nosuchkey +{{< /clients-example >}} + +Give these commands a try in the interactive console: + {{% redis-cli %}} SET key1 "Hello" EXISTS key1 diff --git a/local_examples/new_tces/NRedisStack/CmdsGenericExample.cs b/local_examples/new_tces/NRedisStack/CmdsGenericExample.cs new file mode 100644 index 0000000000..11723b0221 --- /dev/null +++ b/local_examples/new_tces/NRedisStack/CmdsGenericExample.cs @@ -0,0 +1,156 @@ +// EXAMPLE: cmds_generic +// HIDE_START +using NRedisStack.Tests; +using StackExchange.Redis; + +public class CmdsGenericExample +{ + public void Run() + { + var muxer = ConnectionMultiplexer.Connect("localhost:6379"); + var db = muxer.GetDatabase(); +// HIDE_END + + // Tests for 'copy' step. + + // STEP_START del + bool delResult1 = db.StringSet("key1", "Hello"); + Console.WriteLine(delResult1); // >>> true + + bool delResult2 = db.StringSet("key2", "World"); + Console.WriteLine(delResult2); // >>> true + + long delResult3 = db.KeyDelete(["key1", "key2", "key3"]); + Console.WriteLine(delResult3); // >>> 2 + + // Tests for 'del' step. + // STEP_END + + // Tests for 'dump' step. + + // STEP_START exists + bool existsResult1 = db.StringSet("key1", "Hello"); + Console.WriteLine(existsResult1); // >>> true + + bool existsResult2 = db.KeyExists("key1"); + Console.WriteLine(existsResult2); // >>> true + + bool existsResult3 = db.KeyExists("nosuchkey"); + Console.WriteLine(existsResult3); // >>> false + + bool existsResult4 = db.StringSet("key2", "World"); + Console.WriteLine(existsResult4); // >>> true + + long existsResult5 = db.KeyExists(["key1", "key2", "nosuchkey"]); + Console.WriteLine(existsResult5); // >>> 2 + + // Tests for 'exists' step. + // STEP_END + + // STEP_START expire + bool expireResult1 = db.StringSet("mykey", "Hello"); + Console.WriteLine(expireResult1); // >>> true + + bool expireResult2 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10)); + Console.WriteLine(expireResult2); // >>> true + + TimeSpan expireResult3 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; + Console.WriteLine(Math.Round(expireResult3.TotalSeconds)); // >>> 10 + + bool expireResult4 = db.StringSet("mykey", "Hello World"); + Console.WriteLine(expireResult4); // >>> true + + TimeSpan expireResult5 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; + Console.WriteLine(Math.Round(expireResult5.TotalSeconds).ToString()); // >>> 0 + + bool expireResult6 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10), ExpireWhen.HasExpiry); + Console.WriteLine(expireResult6); // >>> false + + TimeSpan expireResult7 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; + Console.WriteLine(Math.Round(expireResult7.TotalSeconds)); // >>> 0 + + bool expireResult8 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10), ExpireWhen.HasNoExpiry); + Console.WriteLine(expireResult8); // >>> true + + TimeSpan expireResult9 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; + Console.WriteLine(Math.Round(expireResult9.TotalSeconds)); // >>> 10 + + // Tests for 'expire' step. + // STEP_END + + // Tests for 'expireat' step. + + // Tests for 'expiretime' step. + + // Tests for 'keys' step. + + // Tests for 'migrate' step. + + // Tests for 'move' step. + + // Tests for 'object_encoding' step. + + // Tests for 'object_freq' step. + + // Tests for 'object_idletime' step. + + // Tests for 'object_refcount' step. + + // Tests for 'persist' step. + + // Tests for 'pexpire' step. + + // Tests for 'pexpireat' step. + + // Tests for 'pexpiretime' step. + + // Tests for 'pttl' step. + + // Tests for 'randomkey' step. + + // Tests for 'rename' step. + + // Tests for 'renamenx' step. + + // Tests for 'restore' step. + + // Tests for 'scan1' step. + + // Tests for 'scan2' step. + + // Tests for 'scan3' step. + + // Tests for 'scan4' step. + + // Tests for 'sort' step. + + // Tests for 'sort_ro' step. + + // Tests for 'touch' step. + + // STEP_START ttl + bool ttlResult1 = db.StringSet("mykey", "Hello"); + Console.WriteLine(ttlResult1); // >>> true + + bool ttlResult2 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10)); + Console.WriteLine(ttlResult2); + + TimeSpan ttlResult3 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; + string ttlRes = Math.Round(ttlResult3.TotalSeconds).ToString(); + Console.WriteLine(Math.Round(ttlResult3.TotalSeconds)); // >>> 10 + + // Tests for 'ttl' step. + // STEP_END + + // Tests for 'type' step. + + // Tests for 'unlink' step. + + // Tests for 'wait' step. + + // Tests for 'waitaof' step. + +// HIDE_START + } +} +// HIDE_END diff --git a/local_examples/new_tces/go-redis/cmds_generic_test.go b/local_examples/new_tces/go-redis/cmds_generic_test.go new file mode 100644 index 0000000000..8edc794173 --- /dev/null +++ b/local_examples/new_tces/go-redis/cmds_generic_test.go @@ -0,0 +1,262 @@ +// EXAMPLE: cmds_generic +package example_commands_test + +import ( + "context" + "fmt" + "math" + "time" + + "github.com/redis/go-redis/v9" +) + +func ExampleClient_del_cmd() { + ctx := context.Background() + + rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", // no password docs + DB: 0, // use default DB + }) + + // REMOVE_START + // make sure we are working with fresh database + rdb.FlushDB(ctx) + rdb.Del(ctx, "key1", "key2", "key3") + // REMOVE_END + + // STEP_START del + delResult1, err := rdb.Set(ctx, "key1", "Hello", 0).Result() + + if err != nil { + panic(err) + } + + fmt.Println(delResult1) // >>> OK + + delResult2, err := rdb.Set(ctx, "key2", "World", 0).Result() + + if err != nil { + panic(err) + } + + fmt.Println(delResult2) // >>> OK + + delResult3, err := rdb.Del(ctx, "key1", "key2", "key3").Result() + + if err != nil { + panic(err) + } + + fmt.Println(delResult3) // >>> 2 + // STEP_END + + // Output: + // OK + // OK + // 2 +} + +// STEP_START exists +func ExampleClient_exists_cmd() { + ctx := context.Background() + + rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", // no password docs + DB: 0, // use default DB + }) + + // REMOVE_START + // make sure we are working with fresh database + rdb.FlushDB(ctx) + rdb.Del(ctx, "key1", "key2", "nosuchkey") + // REMOVE_END + + existsResult1, err := rdb.Set(ctx, "key1", "Hello", 0).Result() + + if err != nil { + panic(err) + } + + fmt.Println(existsResult1) // >>> OK + + existsResult2, err := rdb.Exists(ctx, "key1").Result() + + if err != nil { + panic(err) + } + + fmt.Println(existsResult2) // >>> 1 + + existsResult3, err := rdb.Exists(ctx, "nosuchkey").Result() + + if err != nil { + panic(err) + } + + fmt.Println(existsResult3) // >>> 0 + + existsResult4, err := rdb.Set(ctx, "key2", "World", 0).Result() + + if err != nil { + panic(err) + } + + fmt.Println(existsResult4) // >>> OK + + existsResult5, err := rdb.Exists(ctx, "key1", "key2", "nosuchkey").Result() + + if err != nil { + panic(err) + } + + fmt.Println(existsResult5) // >>> 2 + + // Output: + // OK + // 1 + // 0 + // OK + // 2 +} +// STEP_END + +func ExampleClient_expire_cmd() { + ctx := context.Background() + + rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", // no password docs + DB: 0, // use default DB + }) + + // REMOVE_START + // start with fresh database + rdb.FlushDB(ctx) + rdb.Del(ctx, "mykey") + // REMOVE_END + + // STEP_START expire + expireResult1, err := rdb.Set(ctx, "mykey", "Hello", 0).Result() + + if err != nil { + panic(err) + } + + fmt.Println(expireResult1) // >>> OK + + expireResult2, err := rdb.Expire(ctx, "mykey", 10*time.Second).Result() + + if err != nil { + panic(err) + } + + fmt.Println(expireResult2) // >>> true + + expireResult3, err := rdb.TTL(ctx, "mykey").Result() + + if err != nil { + panic(err) + } + + fmt.Println(math.Round(expireResult3.Seconds())) // >>> 10 + + expireResult4, err := rdb.Set(ctx, "mykey", "Hello World", 0).Result() + + if err != nil { + panic(err) + } + + fmt.Println(expireResult4) // >>> OK + + expireResult5, err := rdb.TTL(ctx, "mykey").Result() + + if err != nil { + panic(err) + } + + fmt.Println(expireResult5) // >>> -1ns + + expireResult6, err := rdb.ExpireXX(ctx, "mykey", 10*time.Second).Result() + + if err != nil { + panic(err) + } + + fmt.Println(expireResult6) // >>> false + + expireResult7, err := rdb.TTL(ctx, "mykey").Result() + + if err != nil { + panic(err) + } + + fmt.Println(expireResult7) // >>> -1ns + + expireResult8, err := rdb.ExpireNX(ctx, "mykey", 10*time.Second).Result() + + if err != nil { + panic(err) + } + + fmt.Println(expireResult8) // >>> true + + expireResult9, err := rdb.TTL(ctx, "mykey").Result() + + if err != nil { + panic(err) + } + + fmt.Println(math.Round(expireResult9.Seconds())) // >>> 10 + // STEP_END + + // Output: + // OK + // true + // 10 + // OK + // -1ns + // false + // -1ns + // true + // 10 +} + +func ExampleClient_ttl_cmd() { + ctx := context.Background() + + rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", // no password docs + DB: 0, // use default DB + }) + + // REMOVE_START + // start with fresh database + rdb.FlushDB(ctx) + rdb.Del(ctx, "mykey") + // REMOVE_END + + // STEP_START ttl + ttlResult1, err := rdb.Set(ctx, "mykey", "Hello", 10*time.Second).Result() + + if err != nil { + panic(err) + } + + fmt.Println(ttlResult1) // >>> OK + + ttlResult2, err := rdb.TTL(ctx, "mykey").Result() + + if err != nil { + panic(err) + } + + fmt.Println(math.Round(ttlResult2.Seconds())) // >>> 10 + // STEP_END + + // Output: + // OK + // 10 +} diff --git a/local_examples/new_tces/jedis/CmdsGenericExample.java b/local_examples/new_tces/jedis/CmdsGenericExample.java new file mode 100644 index 0000000000..54bb2eb506 --- /dev/null +++ b/local_examples/new_tces/jedis/CmdsGenericExample.java @@ -0,0 +1,94 @@ +// EXAMPLE: cmds_generic +// HIDE_START +import redis.clients.jedis.UnifiedJedis; +import redis.clients.jedis.args.ExpiryOption; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class CmdsGenericExample { + + public void run() { + UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); +// HIDE_END + + // STEP_START del + String delResult1 = jedis.set("key1", "Hello"); + System.out.println(delResult1); // >>> OK + + String delResult2 = jedis.set("key2", "World"); + System.out.println(delResult2); // >>> OK + + long delResult3 = jedis.del("key1", "key2", "key3"); + System.out.println(delResult3); // >>> 2 + + // Tests for 'del' step. + // STEP_END + + // STEP_START exists + String existsResult1 = jedis.set("key1", "Hello"); + System.out.println(existsResult1); // >>> OK + + boolean existsResult2 = jedis.exists("key1"); + System.out.println(existsResult2); // >>> true + + boolean existsResult3 = jedis.exists("nosuchkey"); + System.out.println(existsResult3); // >>> false + + String existsResult4 = jedis.set("key2", "World"); + System.out.println(existsResult4); // >>> OK + + long existsResult5 = jedis.exists("key1", "key2", "nosuchkey"); + System.out.println(existsResult5); // >>> 2 + + // Tests for 'exists' step. + // STEP_END + + // STEP_START expire + String expireResult1 = jedis.set("mykey", "Hello"); + System.out.println(expireResult1); // >>> OK + + long expireResult2 = jedis.expire("mykey", 10); + System.out.println(expireResult2); // >>> 1 + + long expireResult3 = jedis.ttl("mykey"); + System.out.println(expireResult3); // >>> 10 + + String expireResult4 = jedis.set("mykey", "Hello World"); + System.out.println(expireResult4); // >>> OK + + long expireResult5 = jedis.ttl("mykey"); + System.out.println(expireResult5); // >>> -1 + + long expireResult6 = jedis.expire("mykey", 10, ExpiryOption.XX); + System.out.println(expireResult6); // >>> 0 + + long expireResult7 = jedis.ttl("mykey"); + System.out.println(expireResult7); // >>> -1 + + long expireResult8 = jedis.expire("mykey", 10, ExpiryOption.NX); + System.out.println(expireResult8); // >>> 1 + + long expireResult9 = jedis.ttl("mykey"); + System.out.println(expireResult9); // >>> 10 + + // Tests for 'expire' step. + // STEP_END + + // STEP_START ttl + String ttlResult1 = jedis.set("mykey", "Hello"); + System.out.println(ttlResult1); // >>> OK + + long ttlResult2 = jedis.expire("mykey", 10); + System.out.println(ttlResult2); // >>> 1 + + long ttlResult3 = jedis.ttl("mykey"); + System.out.println(ttlResult3); // >>> 10 + + // Tests for 'ttl' step. + // STEP_END + +// HIDE_START + jedis.close(); + } +} +// HIDE_END diff --git a/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-async-Example.java b/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-async-Example.java new file mode 100644 index 0000000000..5ddfa56425 --- /dev/null +++ b/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-async-Example.java @@ -0,0 +1,127 @@ +// EXAMPLE: cmds_generic +// HIDE_START +import io.lettuce.core.RedisClient; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.api.async.RedisAsyncCommands; + +import java.util.concurrent.CompletableFuture; + +import static org.junit.jupiter.api.Assertions.assertThat; + +public class CmdsGenericAsyncExample { + + public void run() { + RedisClient redisClient = RedisClient.create("redis://localhost:6379"); + + try (StatefulRedisConnection connection = redisClient.connect()) { + RedisAsyncCommands asyncCommands = connection.async(); +// HIDE_END + + // STEP_START exists + CompletableFuture existsExample = asyncCommands.set("key1", "Hello").thenCompose(res1 -> { + System.out.println(res1); // >>> OK + // REMOVE_START + assertThat(res1).isEqualTo("OK"); + // REMOVE_END + + return asyncCommands.exists("key1"); + }).thenCompose(res2 -> { + System.out.println(res2); // >>> 1 + // REMOVE_START + assertThat(res2).isEqualTo(1L); + // REMOVE_END + + return asyncCommands.exists("nosuchkey"); + }).thenCompose(res3 -> { + System.out.println(res3); // >>> 0 + // REMOVE_START + assertThat(res3).isEqualTo(0L); + // REMOVE_END + + return asyncCommands.set("key2", "World"); + }).thenCompose(res4 -> { + System.out.println(res4); // >>> OK + // REMOVE_START + assertThat(res4).isEqualTo("OK"); + // REMOVE_END + + return asyncCommands.exists("key1", "key2", "nosuchkey"); + }).thenAccept(res5 -> { + System.out.println(res5); // >>> 2 + // REMOVE_START + assertThat(res5).isEqualTo(2L); + // REMOVE_END + }).toCompletableFuture(); + // STEP_END + +// HIDE_START + existsExample.join(); + } finally { + redisClient.shutdown(); + } + } +} +// HIDE_END +// HIDE_START +import io.lettuce.core.RedisClient; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.api.async.RedisAsyncCommands; + +import java.util.concurrent.CompletableFuture; + +import static org.junit.jupiter.api.Assertions.assertThat; + +public class CmdsGenericAsyncExample { + + public void run() { + RedisClient redisClient = RedisClient.create("redis://localhost:6379"); + + try (StatefulRedisConnection connection = redisClient.connect()) { + RedisAsyncCommands asyncCommands = connection.async(); +// HIDE_END + + // STEP_START exists + CompletableFuture existsExample = asyncCommands.set("key1", "Hello").thenCompose(res1 -> { + System.out.println(res1); // >>> OK + // REMOVE_START + assertThat(res1).isEqualTo("OK"); + // REMOVE_END + + return asyncCommands.exists("key1"); + }).thenCompose(res2 -> { + System.out.println(res2); // >>> 1 + // REMOVE_START + assertThat(res2).isEqualTo(1L); + // REMOVE_END + + return asyncCommands.exists("nosuchkey"); + }).thenCompose(res3 -> { + System.out.println(res3); // >>> 0 + // REMOVE_START + assertThat(res3).isEqualTo(0L); + // REMOVE_END + + return asyncCommands.set("key2", "World"); + }).thenCompose(res4 -> { + System.out.println(res4); // >>> OK + // REMOVE_START + assertThat(res4).isEqualTo("OK"); + // REMOVE_END + + return asyncCommands.exists("key1", "key2", "nosuchkey"); + }).thenAccept(res5 -> { + System.out.println(res5); // >>> 2 + // REMOVE_START + assertThat(res5).isEqualTo(2L); + // REMOVE_END + }).toCompletableFuture(); + // STEP_END + +// HIDE_START + existsExample.join(); + } finally { + redisClient.shutdown(); + } + } +} +// HIDE_END diff --git a/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-reactive-Example.java b/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-reactive-Example.java new file mode 100644 index 0000000000..778ab15251 --- /dev/null +++ b/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-reactive-Example.java @@ -0,0 +1,109 @@ +// EXAMPLE: cmds_generic +// HIDE_START +import io.lettuce.core.RedisClient; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.api.reactive.RedisReactiveCommands; +import reactor.core.publisher.Mono; + +import static org.junit.jupiter.api.Assertions.assertThat; + +public class CmdsGenericReactiveExample { + + public void run() { + RedisClient redisClient = RedisClient.create("redis://localhost:6379"); + + try (StatefulRedisConnection connection = redisClient.connect()) { + RedisReactiveCommands reactiveCommands = connection.reactive(); +// HIDE_END + + // STEP_START exists + Mono existsExample = reactiveCommands.set("key1", "Hello").doOnNext(res1 -> { + System.out.println(res1); // >>> OK + // REMOVE_START + assertThat(res1).isEqualTo("OK"); + // REMOVE_END + }).then(reactiveCommands.exists("key1")).doOnNext(res2 -> { + System.out.println(res2); // >>> 1 + // REMOVE_START + assertThat(res2).isEqualTo(1L); + // REMOVE_END + }).then(reactiveCommands.exists("nosuchkey")).doOnNext(res3 -> { + System.out.println(res3); // >>> 0 + // REMOVE_START + assertThat(res3).isEqualTo(0L); + // REMOVE_END + }).then(reactiveCommands.set("key2", "World")).doOnNext(res4 -> { + System.out.println(res4); // >>> OK + // REMOVE_START + assertThat(res4).isEqualTo("OK"); + // REMOVE_END + }).then(reactiveCommands.exists("key1", "key2", "nosuchkey")).doOnNext(res5 -> { + System.out.println(res5); // >>> 2 + // REMOVE_START + assertThat(res5).isEqualTo(2L); + // REMOVE_END + }).then(); + // STEP_END + +// HIDE_START + existsExample.block(); + } finally { + redisClient.shutdown(); + } + } +} +// HIDE_END +// HIDE_START +import io.lettuce.core.RedisClient; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.api.reactive.RedisReactiveCommands; +import reactor.core.publisher.Mono; + +import static org.junit.jupiter.api.Assertions.assertThat; + +public class CmdsGenericReactiveExample { + + public void run() { + RedisClient redisClient = RedisClient.create("redis://localhost:6379"); + + try (StatefulRedisConnection connection = redisClient.connect()) { + RedisReactiveCommands reactiveCommands = connection.reactive(); +// HIDE_END + + // STEP_START exists + Mono existsExample = reactiveCommands.set("key1", "Hello").doOnNext(res1 -> { + System.out.println(res1); // >>> OK + // REMOVE_START + assertThat(res1).isEqualTo("OK"); + // REMOVE_END + }).then(reactiveCommands.exists("key1")).doOnNext(res2 -> { + System.out.println(res2); // >>> 1 + // REMOVE_START + assertThat(res2).isEqualTo(1L); + // REMOVE_END + }).then(reactiveCommands.exists("nosuchkey")).doOnNext(res3 -> { + System.out.println(res3); // >>> 0 + // REMOVE_START + assertThat(res3).isEqualTo(0L); + // REMOVE_END + }).then(reactiveCommands.set("key2", "World")).doOnNext(res4 -> { + System.out.println(res4); // >>> OK + // REMOVE_START + assertThat(res4).isEqualTo("OK"); + // REMOVE_END + }).then(reactiveCommands.exists("key1", "key2", "nosuchkey")).doOnNext(res5 -> { + System.out.println(res5); // >>> 2 + // REMOVE_START + assertThat(res5).isEqualTo(2L); + // REMOVE_END + }).then(); + // STEP_END + +// HIDE_START + existsExample.block(); + } finally { + redisClient.shutdown(); + } + } +} +// HIDE_END diff --git a/local_examples/new_tces/node-redis/cmds_generic.js b/local_examples/new_tces/node-redis/cmds_generic.js new file mode 100644 index 0000000000..ba35a19841 --- /dev/null +++ b/local_examples/new_tces/node-redis/cmds_generic.js @@ -0,0 +1,186 @@ +// EXAMPLE: cmds_generic +// REMOVE_START +import assert from "node:assert"; +// REMOVE_END + +// HIDE_START +import { createClient } from 'redis'; + +const client = createClient(); +await client.connect().catch(console.error); +// HIDE_END + +// STEP_START del +const delRes1 = await client.set('key1', 'Hello'); +console.log(delRes1); // OK + +const delRes2 = await client.set('key2', 'World'); +console.log(delRes2); // OK + +const delRes3 = await client.del(['key1', 'key2', 'key3']); +console.log(delRes3); // 2 +// REMOVE_START +assert.equal(delRes3, 2); +// REMOVE_END +// STEP_END + +// STEP_START exists +const existsRes1 = await client.set('key1', 'Hello'); +console.log(existsRes1); // OK + +const existsRes2 = await client.exists('key1'); +console.log(existsRes2); // 1 + +const existsRes3 = await client.exists('nosuchkey'); +console.log(existsRes3); // 0 + +const existsRes4 = await client.set('key2', 'World'); +console.log(existsRes4); // OK + +const existsRes5 = await client.exists(['key1', 'key2', 'nosuchkey']); +console.log(existsRes5); // 2 +// REMOVE_START +assert.equal(existsRes5, 2); +await client.del(['key1', 'key2']); +// REMOVE_END +// STEP_END + +// STEP_START expire +const expireRes1 = await client.set('mykey', 'Hello'); +console.log(expireRes1); // OK + +const expireRes2 = await client.expire('mykey', 10); +console.log(expireRes2); // 1 + +const expireRes3 = await client.ttl('mykey'); +console.log(expireRes3); // 10 + +const expireRes4 = await client.set('mykey', 'Hello World'); +console.log(expireRes4); // OK + +const expireRes5 = await client.ttl('mykey'); +console.log(expireRes5); // -1 + +const expireRes6 = await client.expire('mykey', 10, "XX"); +console.log(expireRes6); // 0 + +const expireRes7 = await client.ttl('mykey'); +console.log(expireRes7); // -1 + +const expireRes8 = await client.expire('mykey', 10, "NX"); +console.log(expireRes8); // 1 + +const expireRes9 = await client.ttl('mykey'); +console.log(expireRes9); // 10 +// REMOVE_START +await client.del('mykey'); +// REMOVE_END +// STEP_END + +// STEP_START ttl +const ttlRes1 = await client.set('mykey', 'Hello'); +console.log(ttlRes1); // OK + +const ttlRes2 = await client.expire('mykey', 10); +console.log(ttlRes2); // 1 + +const ttlRes3 = await client.ttl('mykey'); +console.log(ttlRes3); // 10 +// REMOVE_START +await client.del('mykey'); +// REMOVE_END +// STEP_END + +// STEP_START scan1 +const scan1Res1 = await client.sAdd('myset', ['1', '2', '3', 'foo', 'foobar', 'feelsgood']); +console.log(scan1Res1); // 6 + +let scan1Res2 = []; +for await (const values of client.sScanIterator('myset', { MATCH: 'f*' })) { + scan1Res2 = scan1Res2.concat(values); +} +console.log(scan1Res2); // ['foo', 'foobar', 'feelsgood'] +// REMOVE_START +console.assert(scan1Res2.sort().toString() === ['foo', 'foobar', 'feelsgood'].sort().toString()); +await client.del('myset'); +// REMOVE_END +// STEP_END + +// STEP_START scan2 +// REMOVE_START +for (let i = 1; i <= 1000; i++) { + await client.set(`key:${i}`, i); +} +// REMOVE_END + +let cursor = '0'; +let scanResult; + +scanResult = await client.scan(cursor, { MATCH: '*11*' }); +console.log(scanResult.cursor, scanResult.keys); + +scanResult = await client.scan(scanResult.cursor, { MATCH: '*11*' }); +console.log(scanResult.cursor, scanResult.keys); + +scanResult = await client.scan(scanResult.cursor, { MATCH: '*11*' }); +console.log(scanResult.cursor, scanResult.keys); + +scanResult = await client.scan(scanResult.cursor, { MATCH: '*11*' }); +console.log(scanResult.cursor, scanResult.keys); + +scanResult = await client.scan(scanResult.cursor, { MATCH: '*11*', COUNT: 1000 }); +console.log(scanResult.cursor, scanResult.keys); +// REMOVE_START +console.assert(scanResult.keys.length === 18); +cursor = '0'; +const prefix = 'key:*'; +do { + scanResult = await client.scan(cursor, { MATCH: prefix, COUNT: 1000 }); + console.log(scanResult.cursor, scanResult.keys); + cursor = scanResult.cursor; + const keys = scanResult.keys; + if (keys.length) { + await client.del(keys); + } +} while (cursor !== '0'); +// REMOVE_END +// STEP_END + +// STEP_START scan3 +const scan3Res1 = await client.geoAdd('geokey', { longitude: 0, latitude: 0, member: 'value' }); +console.log(scan3Res1); // 1 + +const scan3Res2 = await client.zAdd('zkey', [{ score: 1000, value: 'value' }]); +console.log(scan3Res2); // 1 + +const scan3Res3 = await client.type('geokey'); +console.log(scan3Res3); // zset + +const scan3Res4 = await client.type('zkey'); +console.log(scan3Res4); // zset + +const scan3Res5 = await client.scan('0', { TYPE: 'zset' }); +console.log(scan3Res5.keys); // ['zkey', 'geokey'] +// REMOVE_START +await client.del(['geokey', 'zkey']); +// REMOVE_END +// STEP_END + +// STEP_START scan4 +const scan4Res1 = await client.hSet('myhash', { a: 1, b: 2 }); +console.log(scan4Res1); // 2 + +const scan4Res2 = await client.hScan('myhash', '0'); +console.log(scan4Res2.entries); // [{field: 'a', value: '1'}, {field: 'b', value: '2'}] + +const scan4Res3 = await client.hScan('myhash', '0', { COUNT: 10 }); +const items = scan4Res3.entries.map((item) => item.field) +console.log(items); // ['a', 'b'] +// REMOVE_START +await client.del('myhash'); +// REMOVE_END +// STEP_END + +// HIDE_START +await client.close(); +// HIDE_END diff --git a/local_examples/new_tces/predis/CmdsGenericExample.php b/local_examples/new_tces/predis/CmdsGenericExample.php new file mode 100644 index 0000000000..74969972d9 --- /dev/null +++ b/local_examples/new_tces/predis/CmdsGenericExample.php @@ -0,0 +1,74 @@ + 'tcp', + 'host' => '127.0.0.1', + 'port' => 6379, +]); +// HIDE_END + +// STEP_START del +$delResult1 = $client->set('key1', 'Hello'); +echo $delResult1 . "\n"; // >>> OK + +$delResult2 = $client->set('key2', 'World'); +echo $delResult2 . "\n"; // >>> OK + +$delResult3 = $client->del(['key1', 'key2', 'key3']); +echo $delResult3 . "\n"; // >>> 2 +// STEP_END + +// STEP_START exists +$existsResult1 = $client->set('key1', 'Hello'); +echo $existsResult1 . "\n"; // >>> OK + +$existsResult2 = $client->exists('key1'); +echo $existsResult2 . "\n"; // >>> 1 + +$existsResult3 = $client->exists('nosuchkey'); +echo $existsResult3 . "\n"; // >>> 0 + +$existsResult4 = $client->set('key2', 'World'); +echo $existsResult4 . "\n"; // >>> OK + +$existsResult5 = $client->exists(['key1', 'key2', 'nosuchkey']); +echo $existsResult5 . "\n"; // >>> 2 +// STEP_END + +// STEP_START expire +$expireResult1 = $client->set('mykey', 'Hello'); +echo $expireResult1 . "\n"; // >>> OK + +$expireResult2 = $client->expire('mykey', 10); +echo $expireResult2 . "\n"; // >>> 1 + +$expireResult3 = $client->ttl('mykey'); +echo $expireResult3 . "\n"; // >>> 10 + +$expireResult4 = $client->set('mykey', 'Hello World'); +echo $expireResult4 . "\n"; // >>> OK + +$expireResult5 = $client->ttl('mykey'); +echo $expireResult5 . "\n"; // >>> -1 +// STEP_END + +// STEP_START ttl +$ttlResult1 = $client->set('mykey', 'Hello'); +echo $ttlResult1 . "\n"; // >>> OK + +$ttlResult2 = $client->expire('mykey', 10); +echo $ttlResult2 . "\n"; // >>> 1 + +$ttlResult3 = $client->ttl('mykey'); +echo $ttlResult3 . "\n"; // >>> 10 +// STEP_END + +// HIDE_START +$client->disconnect(); +// HIDE_END +?> diff --git a/local_examples/new_tces/redis-py/cmds_generic.py b/local_examples/new_tces/redis-py/cmds_generic.py new file mode 100644 index 0000000000..6ea3333753 --- /dev/null +++ b/local_examples/new_tces/redis-py/cmds_generic.py @@ -0,0 +1,214 @@ +# EXAMPLE: cmds_generic +# HIDE_START +import redis + +r = redis.Redis(decode_responses=True) +# HIDE_END + +# STEP_START del +res = r.set("key1", "Hello") +print(res) +# >>> True + +res = r.set("key2", "World") +print(res) +# >>> True + +res = r.delete("key1", "key2", "key3") +print(res) +# >>> 2 +# REMOVE_START +assert res == 2 +# REMOVE_END +# STEP_END + +# STEP_START exists +res = r.set("key1", "Hello") +print(res) +# >>> True + +res = r.exists("key1") +print(res) +# >>> 1 + +res = r.exists("nosuchkey") +print(res) +# >>> 0 + +res = r.set("key2", "World") +print(res) +# >>> True + +res = r.exists("key1", "key2", "nosuchkey") +print(res) +# >>> 2 +# REMOVE_START +assert r.exists("key1", "key2", "nosuchkey") == 2 +r.delete("key1", "key2") +# REMOVE_END +# STEP_END + +# STEP_START expire +res = r.set("mykey", "Hello") +print(res) +# >>> True + +res = r.expire("mykey", 10) +print(res) +# >>> True + +res = r.ttl("mykey") +print(res) +# >>> 10 +# REMOVE_START +assert res == 10 +# REMOVE_END + +res = r.set("mykey", "Hello World") +print(res) +# >>> True + +res = r.ttl("mykey") +print(res) +# >>> -1 +# REMOVE_START +assert res == -1 +# REMOVE_END + +res = r.expire("mykey", 10, xx=True) +print(res) +# >>> False +# REMOVE_START +assert res == False +# REMOVE_END + +res = r.ttl("mykey") +print(res) +# >>> -1 +# REMOVE_START +assert res == -1 +# REMOVE_END + +res = r.expire("mykey", 10, nx=True) +print(res) +# >>> True +# REMOVE_START +assert res == True +# REMOVE_END + +res = r.ttl("mykey") +print(res) +# >>> 10 +# REMOVE_START +assert res == 10 +r.delete("mykey") +# REMOVE_END +# STEP_END + +# STEP_START ttl +res = r.set("mykey", "Hello") +print(res) +# >>> True + +res = r.expire("mykey", 10) +print(res) +# >>> True + +res = r.ttl("mykey") +print(res) +# >>> 10 +# REMOVE_START +assert res == 10 +r.delete("mykey") +# REMOVE_END +# STEP_END + +# STEP_START scan1 +res = r.sadd("myset", *set([1, 2, 3, "foo", "foobar", "feelsgood"])) +print(res) +# >>> 6 + +res = list(r.sscan_iter("myset", match="f*")) +print(res) +# >>> ['foobar', 'foo', 'feelsgood'] +# REMOVE_START +assert set(res) == {"foo", "foobar", "feelsgood"} +r.delete("myset") +# REMOVE_END +# STEP_END + +# STEP_START scan2 +# REMOVE_START +for i in range(1, 1001): + r.set(f"key:{i}", i) +# REMOVE_END + +cursor, key = r.scan(cursor=0, match='*11*') +print(cursor, key) + +cursor, key = r.scan(cursor, match='*11*') +print(cursor, key) + +cursor, key = r.scan(cursor, match='*11*') +print(cursor, key) + +cursor, key = r.scan(cursor, match='*11*') +print(cursor, key) + +cursor, keys = r.scan(cursor, match='*11*', count=1000) +print(cursor, keys) + +# REMOVE_START +assert len(keys) == 18 +cursor = '0' +prefix = "key:*" +while cursor != 0: + cursor, keys = r.scan(cursor=cursor, match=prefix, count=1000) + if keys: + r.delete(*keys) +# REMOVE_END +# STEP_END + +# STEP_START scan3 +res = r.geoadd("geokey", (0, 0, "value")) +print(res) +# >>> 1 + +res = r.zadd("zkey", {"value": 1000}) +print(res) +# >>> 1 + +res = r.type("geokey") +print(res) +# >>> zset + +res = r.type("zkey") +print(res) +# >>> zset + +cursor, keys = r.scan(cursor=0, _type="zset") +print(keys) +# >>> ['zkey', 'geokey'] +# REMOVE_START +assert set(keys) == {"zkey", "geokey"} +r.delete("geokey", "zkey") +# REMOVE_END +# STEP_END + +# STEP_START scan4 +res = r.hset("myhash", mapping={"a": 1, "b": 2}) +print(res) +# >>> 2 + +cursor, keys = r.hscan("myhash", 0) +print(keys) +# >>> {'a': '1', 'b': '2'} + +cursor, keys = r.hscan("myhash", 0, no_values=True) +print(keys) +# >>> ['a', 'b'] +# REMOVE_START +assert keys == ['a', 'b'] +r.delete("myhash") +# REMOVE_END +# STEP_END From 551db12a4637a2a7148ee93d586b20e61a0f4111 Mon Sep 17 00:00:00 2001 From: "David W. Dougherty" Date: Tue, 26 Aug 2025 09:09:10 -0700 Subject: [PATCH 2/4] Fix build errors/warnings --- .../CmdsGeneric-lettuce-async-Example.java | 63 ------------------- .../CmdsGeneric-lettuce-reactive-Example.java | 54 ---------------- .../new_tces/predis/CmdsGenericExample.php | 2 +- 3 files changed, 1 insertion(+), 118 deletions(-) diff --git a/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-async-Example.java b/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-async-Example.java index 5ddfa56425..bbc33d46bd 100644 --- a/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-async-Example.java +++ b/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-async-Example.java @@ -62,66 +62,3 @@ public void run() { } } // HIDE_END -// HIDE_START -import io.lettuce.core.RedisClient; -import io.lettuce.core.api.StatefulRedisConnection; -import io.lettuce.core.api.async.RedisAsyncCommands; - -import java.util.concurrent.CompletableFuture; - -import static org.junit.jupiter.api.Assertions.assertThat; - -public class CmdsGenericAsyncExample { - - public void run() { - RedisClient redisClient = RedisClient.create("redis://localhost:6379"); - - try (StatefulRedisConnection connection = redisClient.connect()) { - RedisAsyncCommands asyncCommands = connection.async(); -// HIDE_END - - // STEP_START exists - CompletableFuture existsExample = asyncCommands.set("key1", "Hello").thenCompose(res1 -> { - System.out.println(res1); // >>> OK - // REMOVE_START - assertThat(res1).isEqualTo("OK"); - // REMOVE_END - - return asyncCommands.exists("key1"); - }).thenCompose(res2 -> { - System.out.println(res2); // >>> 1 - // REMOVE_START - assertThat(res2).isEqualTo(1L); - // REMOVE_END - - return asyncCommands.exists("nosuchkey"); - }).thenCompose(res3 -> { - System.out.println(res3); // >>> 0 - // REMOVE_START - assertThat(res3).isEqualTo(0L); - // REMOVE_END - - return asyncCommands.set("key2", "World"); - }).thenCompose(res4 -> { - System.out.println(res4); // >>> OK - // REMOVE_START - assertThat(res4).isEqualTo("OK"); - // REMOVE_END - - return asyncCommands.exists("key1", "key2", "nosuchkey"); - }).thenAccept(res5 -> { - System.out.println(res5); // >>> 2 - // REMOVE_START - assertThat(res5).isEqualTo(2L); - // REMOVE_END - }).toCompletableFuture(); - // STEP_END - -// HIDE_START - existsExample.join(); - } finally { - redisClient.shutdown(); - } - } -} -// HIDE_END diff --git a/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-reactive-Example.java b/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-reactive-Example.java index 778ab15251..62ab5d7221 100644 --- a/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-reactive-Example.java +++ b/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-reactive-Example.java @@ -53,57 +53,3 @@ public void run() { } } // HIDE_END -// HIDE_START -import io.lettuce.core.RedisClient; -import io.lettuce.core.api.StatefulRedisConnection; -import io.lettuce.core.api.reactive.RedisReactiveCommands; -import reactor.core.publisher.Mono; - -import static org.junit.jupiter.api.Assertions.assertThat; - -public class CmdsGenericReactiveExample { - - public void run() { - RedisClient redisClient = RedisClient.create("redis://localhost:6379"); - - try (StatefulRedisConnection connection = redisClient.connect()) { - RedisReactiveCommands reactiveCommands = connection.reactive(); -// HIDE_END - - // STEP_START exists - Mono existsExample = reactiveCommands.set("key1", "Hello").doOnNext(res1 -> { - System.out.println(res1); // >>> OK - // REMOVE_START - assertThat(res1).isEqualTo("OK"); - // REMOVE_END - }).then(reactiveCommands.exists("key1")).doOnNext(res2 -> { - System.out.println(res2); // >>> 1 - // REMOVE_START - assertThat(res2).isEqualTo(1L); - // REMOVE_END - }).then(reactiveCommands.exists("nosuchkey")).doOnNext(res3 -> { - System.out.println(res3); // >>> 0 - // REMOVE_START - assertThat(res3).isEqualTo(0L); - // REMOVE_END - }).then(reactiveCommands.set("key2", "World")).doOnNext(res4 -> { - System.out.println(res4); // >>> OK - // REMOVE_START - assertThat(res4).isEqualTo("OK"); - // REMOVE_END - }).then(reactiveCommands.exists("key1", "key2", "nosuchkey")).doOnNext(res5 -> { - System.out.println(res5); // >>> 2 - // REMOVE_START - assertThat(res5).isEqualTo(2L); - // REMOVE_END - }).then(); - // STEP_END - -// HIDE_START - existsExample.block(); - } finally { - redisClient.shutdown(); - } - } -} -// HIDE_END diff --git a/local_examples/new_tces/predis/CmdsGenericExample.php b/local_examples/new_tces/predis/CmdsGenericExample.php index 74969972d9..6bade2649e 100644 --- a/local_examples/new_tces/predis/CmdsGenericExample.php +++ b/local_examples/new_tces/predis/CmdsGenericExample.php @@ -1,5 +1,5 @@ - Date: Thu, 11 Sep 2025 13:03:44 -0700 Subject: [PATCH 3/4] Refactored invalid examples and restructured --- .../NRedisStack/CmdsGenericExample.cs | 460 ++++++++++++++++++ .../go-redis/cmds_generic_test.go | 5 +- .../jedis/CmdsGenericExample.java | 54 +- .../lettuce-async/CmdsGenericExample.java} | 29 +- .../lettuce-reactive/CmdsGenericExample.java} | 26 +- .../node-redis/cmds_generic.js | 0 .../cmd_exists/predis/CmdsGenericTest.php | 45 ++ .../redis-py/cmds_generic.py | 0 .../NRedisStack/CmdsGenericExample.cs | 156 ------ .../new_tces/predis/CmdsGenericExample.php | 74 --- 10 files changed, 598 insertions(+), 251 deletions(-) create mode 100644 local_examples/cmd_exists/NRedisStack/CmdsGenericExample.cs rename local_examples/{new_tces => cmd_exists}/go-redis/cmds_generic_test.go (99%) rename local_examples/{new_tces => cmd_exists}/jedis/CmdsGenericExample.java (69%) rename local_examples/{new_tces/lettuce/CmdsGeneric-lettuce-async-Example.java => cmd_exists/lettuce-async/CmdsGenericExample.java} (81%) rename local_examples/{new_tces/lettuce/CmdsGeneric-lettuce-reactive-Example.java => cmd_exists/lettuce-reactive/CmdsGenericExample.java} (86%) rename local_examples/{new_tces => cmd_exists}/node-redis/cmds_generic.js (100%) create mode 100644 local_examples/cmd_exists/predis/CmdsGenericTest.php rename local_examples/{new_tces => cmd_exists}/redis-py/cmds_generic.py (100%) delete mode 100644 local_examples/new_tces/NRedisStack/CmdsGenericExample.cs delete mode 100644 local_examples/new_tces/predis/CmdsGenericExample.php diff --git a/local_examples/cmd_exists/NRedisStack/CmdsGenericExample.cs b/local_examples/cmd_exists/NRedisStack/CmdsGenericExample.cs new file mode 100644 index 0000000000..99c5887034 --- /dev/null +++ b/local_examples/cmd_exists/NRedisStack/CmdsGenericExample.cs @@ -0,0 +1,460 @@ +// EXAMPLE: cmds_generic +// HIDE_START + +using NRedisStack.Tests; +using StackExchange.Redis; + +// HIDE_END + +// REMOVE_START +namespace Doc; +[Collection("DocsTests")] +// REMOVE_END + +// HIDE_START +public class CmdsGenericExample +// REMOVE_START + (EndpointsFixture fixture) : AbstractNRedisStackTest(fixture), IDisposable +// REMOVE_END +{ + // REMOVE_START + + [SkipIfRedisFact(Comparison.LessThan, "7.0.0")] + // REMOVE_END + public void Run() + { + //REMOVE_START + // This is needed because we're constructing ConfigurationOptions in the test before calling GetConnection + SkipIfTargetConnectionDoesNotExist(EndpointsFixture.Env.Standalone); + var _ = GetCleanDatabase(EndpointsFixture.Env.Standalone); + //REMOVE_END + var muxer = ConnectionMultiplexer.Connect("localhost:6379"); + var db = muxer.GetDatabase(); + //REMOVE_START + // Clear any keys here before using them in tests. + + //REMOVE_END + // HIDE_END + + + // STEP_START copy + + // STEP_END + + // Tests for 'copy' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START del + bool delResult1 = db.StringSet("key1", "Hello"); + Console.WriteLine(delResult1); // >>> true + + bool delResult2 = db.StringSet("key2", "World"); + Console.WriteLine(delResult2); // >>> true + + long delResult3 = db.KeyDelete(["key1", "key2", "key3"]); + Console.WriteLine(delResult3); // >>> 2 + // STEP_END + + // Tests for 'del' step. + // REMOVE_START + Assert.True(delResult1); + Assert.True(delResult2); + Assert.Equal(2, delResult3); + // REMOVE_END + + + // STEP_START dump + + // STEP_END + + // Tests for 'dump' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START exists + bool existsResult1 = db.StringSet("key1", "Hello"); + Console.WriteLine(existsResult1); // >>> true + + bool existsResult2 = db.KeyExists("key1"); + Console.WriteLine(existsResult2); // >>> true + + bool existsResult3 = db.KeyExists("nosuchkey"); + Console.WriteLine(existsResult3); // >>> false + + bool existsResult4 = db.StringSet("key2", "World"); + Console.WriteLine(existsResult4); // >>> true + + long existsResult5 = db.KeyExists(["key1", "key2", "nosuchkey"]); + Console.WriteLine(existsResult5); // >>> 2 + // STEP_END + + // Tests for 'exists' step. + // REMOVE_START + Assert.True(existsResult1); + Assert.True(existsResult2); + Assert.False(existsResult3); + Assert.True(existsResult4); + Assert.Equal(2, existsResult5); + // REMOVE_END + + // STEP_START expire + bool expireResult1 = db.StringSet("mykey", "Hello"); + Console.WriteLine(expireResult1); // >>> true + + bool expireResult2 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10)); + Console.WriteLine(expireResult2); // >>> true + + TimeSpan expireResult3 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; + Console.WriteLine(Math.Round(expireResult3.TotalSeconds)); // >>> 10 + + bool expireResult4 = db.StringSet("mykey", "Hello World"); + Console.WriteLine(expireResult4); // >>> true + + TimeSpan expireResult5 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; + Console.WriteLine(Math.Round(expireResult5.TotalSeconds).ToString()); // >>> 0 + + bool expireResult6 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10), ExpireWhen.HasExpiry); + Console.WriteLine(expireResult6); // >>> false + + TimeSpan expireResult7 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; + Console.WriteLine(Math.Round(expireResult7.TotalSeconds)); // >>> 0 + + bool expireResult8 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10), ExpireWhen.HasNoExpiry); + Console.WriteLine(expireResult8); // >>> true + + TimeSpan expireResult9 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; + Console.WriteLine(Math.Round(expireResult9.TotalSeconds)); // >>> 10 + // STEP_END + + // Tests for 'expire' step. + // REMOVE_START + Assert.True(expireResult1); + Assert.True(expireResult2); + Assert.Equal(10, Math.Round(expireResult3.TotalSeconds)); + Assert.True(expireResult4); + Assert.Equal(0, Math.Round(expireResult5.TotalSeconds)); + Assert.False(expireResult6); + Assert.Equal(0, Math.Round(expireResult7.TotalSeconds)); + Assert.True(expireResult8); + Assert.Equal(10, Math.Round(expireResult9.TotalSeconds)); + db.KeyDelete("mykey"); + // REMOVE_END + + + // STEP_START expireat + + // STEP_END + + // Tests for 'expireat' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START expiretime + + // STEP_END + + // Tests for 'expiretime' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START keys + + // STEP_END + + // Tests for 'keys' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START migrate + + // STEP_END + + // Tests for 'migrate' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START move + + // STEP_END + + // Tests for 'move' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START object_encoding + + // STEP_END + + // Tests for 'object_encoding' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START object_freq + + // STEP_END + + // Tests for 'object_freq' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START object_idletime + + // STEP_END + + // Tests for 'object_idletime' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START object_refcount + + // STEP_END + + // Tests for 'object_refcount' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START persist + + // STEP_END + + // Tests for 'persist' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START pexpire + + // STEP_END + + // Tests for 'pexpire' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START pexpireat + + // STEP_END + + // Tests for 'pexpireat' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START pexpiretime + + // STEP_END + + // Tests for 'pexpiretime' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START pttl + + // STEP_END + + // Tests for 'pttl' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START randomkey + + // STEP_END + + // Tests for 'randomkey' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START rename + + // STEP_END + + // Tests for 'rename' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START renamenx + + // STEP_END + + // Tests for 'renamenx' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START restore + + // STEP_END + + // Tests for 'restore' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START scan1 + + // STEP_END + + // Tests for 'scan1' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START scan2 + + // STEP_END + + // Tests for 'scan2' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START scan3 + + // STEP_END + + // Tests for 'scan3' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START scan4 + + // STEP_END + + // Tests for 'scan4' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START sort + + // STEP_END + + // Tests for 'sort' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START sort_ro + + // STEP_END + + // Tests for 'sort_ro' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START touch + + // STEP_END + + // Tests for 'touch' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START ttl + bool ttlResult1 = db.StringSet("mykey", "Hello"); + Console.WriteLine(ttlResult1); // >>> true + + bool ttlResult2 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10)); + Console.WriteLine(ttlResult2); + + TimeSpan ttlResult3 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; + string ttlRes = Math.Round(ttlResult3.TotalSeconds).ToString(); + Console.WriteLine(Math.Round(ttlResult3.TotalSeconds)); // >>> 10 + // STEP_END + + // Tests for 'ttl' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START type + + // STEP_END + + // Tests for 'type' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START unlink + + // STEP_END + + // Tests for 'unlink' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START wait + + // STEP_END + + // Tests for 'wait' step. + // REMOVE_START + + // REMOVE_END + + + // STEP_START waitaof + + // STEP_END + + // Tests for 'waitaof' step. + // REMOVE_START + + // REMOVE_END + + + // HIDE_START + } +} +// HIDE_END diff --git a/local_examples/new_tces/go-redis/cmds_generic_test.go b/local_examples/cmd_exists/go-redis/cmds_generic_test.go similarity index 99% rename from local_examples/new_tces/go-redis/cmds_generic_test.go rename to local_examples/cmd_exists/go-redis/cmds_generic_test.go index 8edc794173..005892fad5 100644 --- a/local_examples/new_tces/go-redis/cmds_generic_test.go +++ b/local_examples/cmd_exists/go-redis/cmds_generic_test.go @@ -1,4 +1,5 @@ // EXAMPLE: cmds_generic +// HIDE_START package example_commands_test import ( @@ -10,6 +11,8 @@ import ( "github.com/redis/go-redis/v9" ) +// HIDE_END + func ExampleClient_del_cmd() { ctx := context.Background() @@ -112,6 +115,7 @@ func ExampleClient_exists_cmd() { } fmt.Println(existsResult5) // >>> 2 + // STEP_END // Output: // OK @@ -120,7 +124,6 @@ func ExampleClient_exists_cmd() { // OK // 2 } -// STEP_END func ExampleClient_expire_cmd() { ctx := context.Background() diff --git a/local_examples/new_tces/jedis/CmdsGenericExample.java b/local_examples/cmd_exists/jedis/CmdsGenericExample.java similarity index 69% rename from local_examples/new_tces/jedis/CmdsGenericExample.java rename to local_examples/cmd_exists/jedis/CmdsGenericExample.java index 54bb2eb506..eaee1d5290 100644 --- a/local_examples/new_tces/jedis/CmdsGenericExample.java +++ b/local_examples/cmd_exists/jedis/CmdsGenericExample.java @@ -1,14 +1,27 @@ // EXAMPLE: cmds_generic +// REMOVE_START +package io.redis.examples; + +import org.junit.jupiter.api.Test; +// REMOVE_END + // HIDE_START import redis.clients.jedis.UnifiedJedis; import redis.clients.jedis.args.ExpiryOption; import static org.junit.jupiter.api.Assertions.assertEquals; +// HIDE_END +// HIDE_START public class CmdsGenericExample { + @Test public void run() { UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + + //REMOVE_START + // Clear any keys here before using them in tests. + //REMOVE_END // HIDE_END // STEP_START del @@ -20,9 +33,15 @@ public void run() { long delResult3 = jedis.del("key1", "key2", "key3"); System.out.println(delResult3); // >>> 2 + // STEP_END // Tests for 'del' step. - // STEP_END + // REMOVE_START + assertEquals("OK", delResult1); + assertEquals("OK", delResult2); + assertEquals(2, delResult3); + // REMOVE_END + // STEP_START exists String existsResult1 = jedis.set("key1", "Hello"); @@ -39,9 +58,17 @@ public void run() { long existsResult5 = jedis.exists("key1", "key2", "nosuchkey"); System.out.println(existsResult5); // >>> 2 + // STEP_END // Tests for 'exists' step. - // STEP_END + // REMOVE_START + assertEquals("OK", existsResult1); + assertEquals(true, existsResult2); + assertEquals(false, existsResult3); + assertEquals("OK", existsResult4); + assertEquals(2, existsResult5); + // REMOVE_END + // STEP_START expire String expireResult1 = jedis.set("mykey", "Hello"); @@ -70,9 +97,22 @@ public void run() { long expireResult9 = jedis.ttl("mykey"); System.out.println(expireResult9); // >>> 10 + // STEP_END // Tests for 'expire' step. - // STEP_END + // REMOVE_START + assertEquals("OK", expireResult1); + assertEquals(1, expireResult2); + assertEquals(10, expireResult3); + assertEquals("OK", expireResult4); + assertEquals(-1, expireResult5); + assertEquals(0, expireResult6); + assertEquals(-1, expireResult7); + assertEquals(1, expireResult8); + assertEquals(10, expireResult9); + jedis.del("mykey"); + // REMOVE_END + // STEP_START ttl String ttlResult1 = jedis.set("mykey", "Hello"); @@ -83,9 +123,15 @@ public void run() { long ttlResult3 = jedis.ttl("mykey"); System.out.println(ttlResult3); // >>> 10 + // STEP_END // Tests for 'ttl' step. - // STEP_END + // REMOVE_START + assertEquals("OK", ttlResult1); + assertEquals(1, ttlResult2); + assertEquals(10, ttlResult3); + jedis.del("mykey"); + // REMOVE_END // HIDE_START jedis.close(); diff --git a/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-async-Example.java b/local_examples/cmd_exists/lettuce-async/CmdsGenericExample.java similarity index 81% rename from local_examples/new_tces/lettuce/CmdsGeneric-lettuce-async-Example.java rename to local_examples/cmd_exists/lettuce-async/CmdsGenericExample.java index bbc33d46bd..254aaa4339 100644 --- a/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-async-Example.java +++ b/local_examples/cmd_exists/lettuce-async/CmdsGenericExample.java @@ -1,21 +1,37 @@ // EXAMPLE: cmds_generic -// HIDE_START -import io.lettuce.core.RedisClient; -import io.lettuce.core.api.StatefulRedisConnection; +package io.redis.examples.async; + +// STEP_START import +import io.lettuce.core.*; + import io.lettuce.core.api.async.RedisAsyncCommands; +import io.lettuce.core.api.StatefulRedisConnection; + +import java.util.*; import java.util.concurrent.CompletableFuture; +// STEP_END +// REMOVE_START +import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertThat; +// REMOVE_END -public class CmdsGenericAsyncExample { +public class CmdsGenericExample { + // REMOVE_START + @Test + // REMOVE_END public void run() { + // STEP_START connect RedisClient redisClient = RedisClient.create("redis://localhost:6379"); try (StatefulRedisConnection connection = redisClient.connect()) { RedisAsyncCommands asyncCommands = connection.async(); -// HIDE_END + // STEP_END + // REMOVE_START + asyncCommands.del("key1", "key2", "nosuchkey").toCompletableFuture().join(); + // REMOVE_END // STEP_START exists CompletableFuture existsExample = asyncCommands.set("key1", "Hello").thenCompose(res1 -> { @@ -53,12 +69,9 @@ public void run() { // REMOVE_END }).toCompletableFuture(); // STEP_END - -// HIDE_START existsExample.join(); } finally { redisClient.shutdown(); } } } -// HIDE_END diff --git a/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-reactive-Example.java b/local_examples/cmd_exists/lettuce-reactive/CmdsGenericExample.java similarity index 86% rename from local_examples/new_tces/lettuce/CmdsGeneric-lettuce-reactive-Example.java rename to local_examples/cmd_exists/lettuce-reactive/CmdsGenericExample.java index 62ab5d7221..b0e2655599 100644 --- a/local_examples/new_tces/lettuce/CmdsGeneric-lettuce-reactive-Example.java +++ b/local_examples/cmd_exists/lettuce-reactive/CmdsGenericExample.java @@ -1,20 +1,30 @@ // EXAMPLE: cmds_generic -// HIDE_START -import io.lettuce.core.RedisClient; -import io.lettuce.core.api.StatefulRedisConnection; +package io.redis.examples.reactive; + +import io.lettuce.core.*; import io.lettuce.core.api.reactive.RedisReactiveCommands; +import io.lettuce.core.api.StatefulRedisConnection; +// REMOVE_START +import org.junit.jupiter.api.Test; +// REMOVE_END import reactor.core.publisher.Mono; +import java.util.*; + +// REMOVE_START import static org.junit.jupiter.api.Assertions.assertThat; +// REMOVE_END -public class CmdsGenericReactiveExample { +public class CmdsGenericExample { + // REMOVE_START + @Test + // REMOVE_END public void run() { RedisClient redisClient = RedisClient.create("redis://localhost:6379"); try (StatefulRedisConnection connection = redisClient.connect()) { RedisReactiveCommands reactiveCommands = connection.reactive(); -// HIDE_END // STEP_START exists Mono existsExample = reactiveCommands.set("key1", "Hello").doOnNext(res1 -> { @@ -45,11 +55,11 @@ public void run() { }).then(); // STEP_END -// HIDE_START - existsExample.block(); + Mono.when(existsExample).block(); + } finally { redisClient.shutdown(); } } + } -// HIDE_END diff --git a/local_examples/new_tces/node-redis/cmds_generic.js b/local_examples/cmd_exists/node-redis/cmds_generic.js similarity index 100% rename from local_examples/new_tces/node-redis/cmds_generic.js rename to local_examples/cmd_exists/node-redis/cmds_generic.js diff --git a/local_examples/cmd_exists/predis/CmdsGenericTest.php b/local_examples/cmd_exists/predis/CmdsGenericTest.php new file mode 100644 index 0000000000..e9779b7bd0 --- /dev/null +++ b/local_examples/cmd_exists/predis/CmdsGenericTest.php @@ -0,0 +1,45 @@ +// EXAMPLE: cmds_generic + 'tcp', + 'host' => '127.0.0.1', + 'port' => 6379, + 'password' => '', + 'database' => 0, + ]); + // REMOVE_START + $r->flushall(); + // REMOVE_END + + // STEP_START exists + $existsResult1 = $r->set('key1', 'Hello'); + echo $existsResult1 . PHP_EOL; // >>> OK + + $existsResult2 = $r->exists('key1'); + echo $existsResult2 . PHP_EOL; // >>> 1 + + $existsResult3 = $r->exists('nosuchkey'); + echo $existsResult3 . PHP_EOL; // >>> 0 + + $existsResult4 = $r->set('key2', 'World'); + echo $existsResult4 . PHP_EOL; // >>> OK + + $existsResult5 = $r->exists(['key1', 'key2', 'nosuchkey']); + echo $existsResult5 . PHP_EOL; // >>> 2 + // STEP_END + // REMOVE_START + $this->assertEquals(2, $existsResult5); + // REMOVE_END + + } +} diff --git a/local_examples/new_tces/redis-py/cmds_generic.py b/local_examples/cmd_exists/redis-py/cmds_generic.py similarity index 100% rename from local_examples/new_tces/redis-py/cmds_generic.py rename to local_examples/cmd_exists/redis-py/cmds_generic.py diff --git a/local_examples/new_tces/NRedisStack/CmdsGenericExample.cs b/local_examples/new_tces/NRedisStack/CmdsGenericExample.cs deleted file mode 100644 index 11723b0221..0000000000 --- a/local_examples/new_tces/NRedisStack/CmdsGenericExample.cs +++ /dev/null @@ -1,156 +0,0 @@ -// EXAMPLE: cmds_generic -// HIDE_START -using NRedisStack.Tests; -using StackExchange.Redis; - -public class CmdsGenericExample -{ - public void Run() - { - var muxer = ConnectionMultiplexer.Connect("localhost:6379"); - var db = muxer.GetDatabase(); -// HIDE_END - - // Tests for 'copy' step. - - // STEP_START del - bool delResult1 = db.StringSet("key1", "Hello"); - Console.WriteLine(delResult1); // >>> true - - bool delResult2 = db.StringSet("key2", "World"); - Console.WriteLine(delResult2); // >>> true - - long delResult3 = db.KeyDelete(["key1", "key2", "key3"]); - Console.WriteLine(delResult3); // >>> 2 - - // Tests for 'del' step. - // STEP_END - - // Tests for 'dump' step. - - // STEP_START exists - bool existsResult1 = db.StringSet("key1", "Hello"); - Console.WriteLine(existsResult1); // >>> true - - bool existsResult2 = db.KeyExists("key1"); - Console.WriteLine(existsResult2); // >>> true - - bool existsResult3 = db.KeyExists("nosuchkey"); - Console.WriteLine(existsResult3); // >>> false - - bool existsResult4 = db.StringSet("key2", "World"); - Console.WriteLine(existsResult4); // >>> true - - long existsResult5 = db.KeyExists(["key1", "key2", "nosuchkey"]); - Console.WriteLine(existsResult5); // >>> 2 - - // Tests for 'exists' step. - // STEP_END - - // STEP_START expire - bool expireResult1 = db.StringSet("mykey", "Hello"); - Console.WriteLine(expireResult1); // >>> true - - bool expireResult2 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10)); - Console.WriteLine(expireResult2); // >>> true - - TimeSpan expireResult3 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; - Console.WriteLine(Math.Round(expireResult3.TotalSeconds)); // >>> 10 - - bool expireResult4 = db.StringSet("mykey", "Hello World"); - Console.WriteLine(expireResult4); // >>> true - - TimeSpan expireResult5 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; - Console.WriteLine(Math.Round(expireResult5.TotalSeconds).ToString()); // >>> 0 - - bool expireResult6 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10), ExpireWhen.HasExpiry); - Console.WriteLine(expireResult6); // >>> false - - TimeSpan expireResult7 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; - Console.WriteLine(Math.Round(expireResult7.TotalSeconds)); // >>> 0 - - bool expireResult8 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10), ExpireWhen.HasNoExpiry); - Console.WriteLine(expireResult8); // >>> true - - TimeSpan expireResult9 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; - Console.WriteLine(Math.Round(expireResult9.TotalSeconds)); // >>> 10 - - // Tests for 'expire' step. - // STEP_END - - // Tests for 'expireat' step. - - // Tests for 'expiretime' step. - - // Tests for 'keys' step. - - // Tests for 'migrate' step. - - // Tests for 'move' step. - - // Tests for 'object_encoding' step. - - // Tests for 'object_freq' step. - - // Tests for 'object_idletime' step. - - // Tests for 'object_refcount' step. - - // Tests for 'persist' step. - - // Tests for 'pexpire' step. - - // Tests for 'pexpireat' step. - - // Tests for 'pexpiretime' step. - - // Tests for 'pttl' step. - - // Tests for 'randomkey' step. - - // Tests for 'rename' step. - - // Tests for 'renamenx' step. - - // Tests for 'restore' step. - - // Tests for 'scan1' step. - - // Tests for 'scan2' step. - - // Tests for 'scan3' step. - - // Tests for 'scan4' step. - - // Tests for 'sort' step. - - // Tests for 'sort_ro' step. - - // Tests for 'touch' step. - - // STEP_START ttl - bool ttlResult1 = db.StringSet("mykey", "Hello"); - Console.WriteLine(ttlResult1); // >>> true - - bool ttlResult2 = db.KeyExpire("mykey", new TimeSpan(0, 0, 10)); - Console.WriteLine(ttlResult2); - - TimeSpan ttlResult3 = db.KeyTimeToLive("mykey") ?? TimeSpan.Zero; - string ttlRes = Math.Round(ttlResult3.TotalSeconds).ToString(); - Console.WriteLine(Math.Round(ttlResult3.TotalSeconds)); // >>> 10 - - // Tests for 'ttl' step. - // STEP_END - - // Tests for 'type' step. - - // Tests for 'unlink' step. - - // Tests for 'wait' step. - - // Tests for 'waitaof' step. - -// HIDE_START - } -} -// HIDE_END diff --git a/local_examples/new_tces/predis/CmdsGenericExample.php b/local_examples/new_tces/predis/CmdsGenericExample.php deleted file mode 100644 index 6bade2649e..0000000000 --- a/local_examples/new_tces/predis/CmdsGenericExample.php +++ /dev/null @@ -1,74 +0,0 @@ -// EXAMPLE: cmds_generic - 'tcp', - 'host' => '127.0.0.1', - 'port' => 6379, -]); -// HIDE_END - -// STEP_START del -$delResult1 = $client->set('key1', 'Hello'); -echo $delResult1 . "\n"; // >>> OK - -$delResult2 = $client->set('key2', 'World'); -echo $delResult2 . "\n"; // >>> OK - -$delResult3 = $client->del(['key1', 'key2', 'key3']); -echo $delResult3 . "\n"; // >>> 2 -// STEP_END - -// STEP_START exists -$existsResult1 = $client->set('key1', 'Hello'); -echo $existsResult1 . "\n"; // >>> OK - -$existsResult2 = $client->exists('key1'); -echo $existsResult2 . "\n"; // >>> 1 - -$existsResult3 = $client->exists('nosuchkey'); -echo $existsResult3 . "\n"; // >>> 0 - -$existsResult4 = $client->set('key2', 'World'); -echo $existsResult4 . "\n"; // >>> OK - -$existsResult5 = $client->exists(['key1', 'key2', 'nosuchkey']); -echo $existsResult5 . "\n"; // >>> 2 -// STEP_END - -// STEP_START expire -$expireResult1 = $client->set('mykey', 'Hello'); -echo $expireResult1 . "\n"; // >>> OK - -$expireResult2 = $client->expire('mykey', 10); -echo $expireResult2 . "\n"; // >>> 1 - -$expireResult3 = $client->ttl('mykey'); -echo $expireResult3 . "\n"; // >>> 10 - -$expireResult4 = $client->set('mykey', 'Hello World'); -echo $expireResult4 . "\n"; // >>> OK - -$expireResult5 = $client->ttl('mykey'); -echo $expireResult5 . "\n"; // >>> -1 -// STEP_END - -// STEP_START ttl -$ttlResult1 = $client->set('mykey', 'Hello'); -echo $ttlResult1 . "\n"; // >>> OK - -$ttlResult2 = $client->expire('mykey', 10); -echo $ttlResult2 . "\n"; // >>> 1 - -$ttlResult3 = $client->ttl('mykey'); -echo $ttlResult3 . "\n"; // >>> 10 -// STEP_END - -// HIDE_START -$client->disconnect(); -// HIDE_END -?> From 8f4089ab9dd9ba49908065b3a508920122221215 Mon Sep 17 00:00:00 2001 From: "David W. Dougherty" Date: Fri, 12 Sep 2025 06:33:48 -0700 Subject: [PATCH 4/4] Apply suggestions from code review --- .../cmd_exists/go-redis/cmds_generic_test.go | 2 +- .../cmd_exists/lettuce-async/CmdsGenericExample.java | 11 +++-------- .../lettuce-reactive/CmdsGenericExample.java | 4 +--- local_examples/cmd_exists/predis/CmdsGenericTest.php | 8 ++++++-- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/local_examples/cmd_exists/go-redis/cmds_generic_test.go b/local_examples/cmd_exists/go-redis/cmds_generic_test.go index 005892fad5..c9b1131247 100644 --- a/local_examples/cmd_exists/go-redis/cmds_generic_test.go +++ b/local_examples/cmd_exists/go-redis/cmds_generic_test.go @@ -60,7 +60,6 @@ func ExampleClient_del_cmd() { // 2 } -// STEP_START exists func ExampleClient_exists_cmd() { ctx := context.Background() @@ -76,6 +75,7 @@ func ExampleClient_exists_cmd() { rdb.Del(ctx, "key1", "key2", "nosuchkey") // REMOVE_END + // STEP_START exists existsResult1, err := rdb.Set(ctx, "key1", "Hello", 0).Result() if err != nil { diff --git a/local_examples/cmd_exists/lettuce-async/CmdsGenericExample.java b/local_examples/cmd_exists/lettuce-async/CmdsGenericExample.java index 254aaa4339..a7a869cd07 100644 --- a/local_examples/cmd_exists/lettuce-async/CmdsGenericExample.java +++ b/local_examples/cmd_exists/lettuce-async/CmdsGenericExample.java @@ -1,20 +1,17 @@ // EXAMPLE: cmds_generic package io.redis.examples.async; -// STEP_START import import io.lettuce.core.*; import io.lettuce.core.api.async.RedisAsyncCommands; import io.lettuce.core.api.StatefulRedisConnection; -import java.util.*; import java.util.concurrent.CompletableFuture; -// STEP_END // REMOVE_START import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; // REMOVE_END public class CmdsGenericExample { @@ -23,15 +20,13 @@ public class CmdsGenericExample { @Test // REMOVE_END public void run() { - // STEP_START connect + // REMOVE_START RedisClient redisClient = RedisClient.create("redis://localhost:6379"); try (StatefulRedisConnection connection = redisClient.connect()) { RedisAsyncCommands asyncCommands = connection.async(); - // STEP_END - // REMOVE_START asyncCommands.del("key1", "key2", "nosuchkey").toCompletableFuture().join(); - // REMOVE_END + // REMOVE_END // STEP_START exists CompletableFuture existsExample = asyncCommands.set("key1", "Hello").thenCompose(res1 -> { diff --git a/local_examples/cmd_exists/lettuce-reactive/CmdsGenericExample.java b/local_examples/cmd_exists/lettuce-reactive/CmdsGenericExample.java index b0e2655599..a03e65634c 100644 --- a/local_examples/cmd_exists/lettuce-reactive/CmdsGenericExample.java +++ b/local_examples/cmd_exists/lettuce-reactive/CmdsGenericExample.java @@ -9,10 +9,8 @@ // REMOVE_END import reactor.core.publisher.Mono; -import java.util.*; - // REMOVE_START -import static org.junit.jupiter.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; // REMOVE_END public class CmdsGenericExample { diff --git a/local_examples/cmd_exists/predis/CmdsGenericTest.php b/local_examples/cmd_exists/predis/CmdsGenericTest.php index e9779b7bd0..e83b738224 100644 --- a/local_examples/cmd_exists/predis/CmdsGenericTest.php +++ b/local_examples/cmd_exists/predis/CmdsGenericTest.php @@ -10,7 +10,7 @@ class CmdsGenericTest // REMOVE_END { public function testCmdsGeneric() { - $r = new Client([ + $r = new PredisClient([ 'scheme' => 'tcp', 'host' => '127.0.0.1', 'port' => 6379, @@ -34,10 +34,14 @@ public function testCmdsGeneric() { $existsResult4 = $r->set('key2', 'World'); echo $existsResult4 . PHP_EOL; // >>> OK - $existsResult5 = $r->exists(['key1', 'key2', 'nosuchkey']); + $existsResult5 = $r->exists('key1', 'key2', 'nosuchkey'); echo $existsResult5 . PHP_EOL; // >>> 2 // STEP_END // REMOVE_START + $this->assertEquals('OK', $existsResult1); + $this->assertEquals(1, $existsResult2); + $this->assertEquals(0, $existsResult3); + $this->assertEquals('OK', $existsResult4); $this->assertEquals(2, $existsResult5); // REMOVE_END