From 3f5789ad060b3036ded67f169baf877f8af5db19 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Wed, 15 Jan 2025 14:23:01 +0000 Subject: [PATCH 1/4] DOC-4445 server management command examples --- .../redis/examples/CmdsServerMgmtExample.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/test/java/io/redis/examples/CmdsServerMgmtExample.java diff --git a/src/test/java/io/redis/examples/CmdsServerMgmtExample.java b/src/test/java/io/redis/examples/CmdsServerMgmtExample.java new file mode 100644 index 0000000000..1890e1869d --- /dev/null +++ b/src/test/java/io/redis/examples/CmdsServerMgmtExample.java @@ -0,0 +1,43 @@ +// EXAMPLE: cmds_servermgmt +// REMOVE_START +package io.redis.examples; + +import org.junit.Assert; +import org.junit.Test; +// REMOVE_END +import java.util.Set; + +// HIDE_START +import redis.clients.jedis.UnifiedJedis; + +public class CmdsServerMgmtExample { + @Test + public void run() { + UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); + + // STEP_START flushall + //REMOVE_START + jedis.set("testkey1", "1"); + jedis.set("testkey2", "2"); + jedis.set("testkey3", "3"); + //REMOVE_END + String flushAllResult1 = jedis.flushAll(); + System.out.println(flushAllResult1); // >>> OK + + Set flushAllResult2 = jedis.keys("*"); + System.out.println(flushAllResult2); // >>> [] + // STEP_END + // REMOVE_START + Assert.assertEquals("OK", flushAllResult1); + Assert.assertEquals("[]", flushAllResult2.toString()); + // REMOVE_END + + // STEP_START info + + // Not currently supported by Jedis. + + // STEP_END + +// HIDE_END + } +} \ No newline at end of file From 8ac8c471c2e2cdac74c1c48ec4be6aa94f4f5397 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 17 Jan 2025 11:41:19 +0000 Subject: [PATCH 2/4] DOC-4445 implemented info command example with Jedis class --- .../io/redis/examples/CmdsServerMgmtExample.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/redis/examples/CmdsServerMgmtExample.java b/src/test/java/io/redis/examples/CmdsServerMgmtExample.java index 1890e1869d..6af9237a97 100644 --- a/src/test/java/io/redis/examples/CmdsServerMgmtExample.java +++ b/src/test/java/io/redis/examples/CmdsServerMgmtExample.java @@ -7,6 +7,7 @@ // REMOVE_END import java.util.Set; +import redis.clients.jedis.Jedis; // HIDE_START import redis.clients.jedis.UnifiedJedis; @@ -33,11 +34,22 @@ public void run() { // REMOVE_END // STEP_START info + // Note: you must use the `Jedis` class to access the `info` + // command rather than `UnifiedJedis`. + Jedis jedis2 = new Jedis("redis://localhost:6379"); - // Not currently supported by Jedis. + String infoResult = jedis2.info(); + + // Check the first 8 characters of the result (the full `info` string + // is much longer than this). + System.out.println(infoResult.substring(0, 8)); // >>> # Server + jedis2.close(); // STEP_END - + // REMOVE_START + Assert.assertEquals("# Server", infoResult.substring(0, 8)); + // REMOVE_END + // HIDE_END } } \ No newline at end of file From a164ae836e225027b8ff306a8212760d93938e96 Mon Sep 17 00:00:00 2001 From: andy-stark-redis <164213578+andy-stark-redis@users.noreply.github.com> Date: Mon, 20 Jan 2025 11:44:30 +0000 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> --- src/test/java/io/redis/examples/CmdsServerMgmtExample.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/redis/examples/CmdsServerMgmtExample.java b/src/test/java/io/redis/examples/CmdsServerMgmtExample.java index 6af9237a97..5754b506e3 100644 --- a/src/test/java/io/redis/examples/CmdsServerMgmtExample.java +++ b/src/test/java/io/redis/examples/CmdsServerMgmtExample.java @@ -17,11 +17,11 @@ public void run() { UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); // STEP_START flushall - //REMOVE_START + // REMOVE_START jedis.set("testkey1", "1"); jedis.set("testkey2", "2"); jedis.set("testkey3", "3"); - //REMOVE_END + // REMOVE_END String flushAllResult1 = jedis.flushAll(); System.out.println(flushAllResult1); // >>> OK From 0db8a4e16bcfcc756b8b07b8cdd5fab4d27fad22 Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Mon, 20 Jan 2025 12:01:55 +0000 Subject: [PATCH 4/4] DOC-4445 implemented feedback --- src/test/java/io/redis/examples/CmdsServerMgmtExample.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/redis/examples/CmdsServerMgmtExample.java b/src/test/java/io/redis/examples/CmdsServerMgmtExample.java index 5754b506e3..3894dc4287 100644 --- a/src/test/java/io/redis/examples/CmdsServerMgmtExample.java +++ b/src/test/java/io/redis/examples/CmdsServerMgmtExample.java @@ -15,6 +15,7 @@ public class CmdsServerMgmtExample { @Test public void run() { UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379"); +// HIDE_END // STEP_START flushall // REMOVE_START @@ -50,6 +51,8 @@ public void run() { Assert.assertEquals("# Server", infoResult.substring(0, 8)); // REMOVE_END -// HIDE_END +// HIDE_START + jedis.close(); } -} \ No newline at end of file +} +// HIDE_END