Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC-4445 server management command examples #4056

Merged
55 changes: 55 additions & 0 deletions src/test/java/io/redis/examples/CmdsServerMgmtExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// EXAMPLE: cmds_servermgmt
// REMOVE_START
package io.redis.examples;

import org.junit.Assert;
import org.junit.Test;
// REMOVE_END
import java.util.Set;

import redis.clients.jedis.Jedis;
// HIDE_START
import redis.clients.jedis.UnifiedJedis;

public class CmdsServerMgmtExample {
@Test
public void run() {
UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379");
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved

// STEP_START flushall
//REMOVE_START
andy-stark-redis marked this conversation as resolved.
Show resolved Hide resolved
jedis.set("testkey1", "1");
jedis.set("testkey2", "2");
jedis.set("testkey3", "3");
//REMOVE_END
andy-stark-redis marked this conversation as resolved.
Show resolved Hide resolved
String flushAllResult1 = jedis.flushAll();
System.out.println(flushAllResult1); // >>> OK

Set<String> flushAllResult2 = jedis.keys("*");
System.out.println(flushAllResult2); // >>> []
// STEP_END
// REMOVE_START
Assert.assertEquals("OK", flushAllResult1);
Assert.assertEquals("[]", flushAllResult2.toString());
// 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");

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
sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading