Skip to content

Commit e6a94d4

Browse files
DOC-4445 server management command examples (#4056)
* DOC-4445 server management command examples * DOC-4445 implemented info command example with Jedis class * Apply suggestions from code review Co-authored-by: M Sazzadul Hoque <[email protected]> * DOC-4445 implemented feedback --------- Co-authored-by: M Sazzadul Hoque <[email protected]>
1 parent e1de59f commit e6a94d4

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// EXAMPLE: cmds_servermgmt
2+
// REMOVE_START
3+
package io.redis.examples;
4+
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
// REMOVE_END
8+
import java.util.Set;
9+
10+
import redis.clients.jedis.Jedis;
11+
// HIDE_START
12+
import redis.clients.jedis.UnifiedJedis;
13+
14+
public class CmdsServerMgmtExample {
15+
@Test
16+
public void run() {
17+
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
18+
// HIDE_END
19+
20+
// STEP_START flushall
21+
// REMOVE_START
22+
jedis.set("testkey1", "1");
23+
jedis.set("testkey2", "2");
24+
jedis.set("testkey3", "3");
25+
// REMOVE_END
26+
String flushAllResult1 = jedis.flushAll();
27+
System.out.println(flushAllResult1); // >>> OK
28+
29+
Set<String> flushAllResult2 = jedis.keys("*");
30+
System.out.println(flushAllResult2); // >>> []
31+
// STEP_END
32+
// REMOVE_START
33+
Assert.assertEquals("OK", flushAllResult1);
34+
Assert.assertEquals("[]", flushAllResult2.toString());
35+
// REMOVE_END
36+
37+
// STEP_START info
38+
// Note: you must use the `Jedis` class to access the `info`
39+
// command rather than `UnifiedJedis`.
40+
Jedis jedis2 = new Jedis("redis://localhost:6379");
41+
42+
String infoResult = jedis2.info();
43+
44+
// Check the first 8 characters of the result (the full `info` string
45+
// is much longer than this).
46+
System.out.println(infoResult.substring(0, 8)); // >>> # Server
47+
48+
jedis2.close();
49+
// STEP_END
50+
// REMOVE_START
51+
Assert.assertEquals("# Server", infoResult.substring(0, 8));
52+
// REMOVE_END
53+
54+
// HIDE_START
55+
jedis.close();
56+
}
57+
}
58+
// HIDE_END

0 commit comments

Comments
 (0)