Added bunch of missing commands and a test to check if Jedis is updated
This commit is contained in:
@@ -563,4 +563,28 @@ public class Client extends Connection {
|
||||
public void configSet(String parameter, String value) {
|
||||
sendCommand("CONFIG", "SET", parameter, value);
|
||||
}
|
||||
|
||||
public void strlen(String key) {
|
||||
sendCommand("STRLEN", key);
|
||||
}
|
||||
|
||||
public void sync() {
|
||||
sendCommand("SYNC");
|
||||
}
|
||||
|
||||
public void lpushx(String key, String string) {
|
||||
sendCommand("LPUSHX", key, string);
|
||||
}
|
||||
|
||||
public void persist(String key) {
|
||||
sendCommand("PERSIST", key);
|
||||
}
|
||||
|
||||
public void rpushx(String key, String string) {
|
||||
sendCommand("RPUSHX", key, string);
|
||||
}
|
||||
|
||||
public void echo(String string) {
|
||||
sendCommand("ECHO", string);
|
||||
}
|
||||
}
|
||||
@@ -790,4 +790,33 @@ public class Jedis {
|
||||
public boolean isConnected() {
|
||||
return client.isConnected();
|
||||
}
|
||||
|
||||
public int strlen(String key) {
|
||||
client.strlen(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public void sync() {
|
||||
client.sync();
|
||||
}
|
||||
|
||||
public int lpushx(String key, String string) {
|
||||
client.lpushx(key, string);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public int persist(String key) {
|
||||
client.persist(key);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public int rpushx(String key, String string) {
|
||||
client.rpushx(key, string);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public String echo(String string) {
|
||||
client.echo(string);
|
||||
return client.getBulkReply();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package redis.clients.jedis.tests;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
import redis.clients.jedis.Transaction;
|
||||
|
||||
public class JedisNewCommandsCheckTest extends Assert {
|
||||
@Test
|
||||
@Ignore(value = "Ignored because still missing information for DEBUG and LINSERT commands")
|
||||
public void checkJedisIsUpdated() throws IOException {
|
||||
String[] commands = getAvailableCommands();
|
||||
Set<String> implementedCommands = getImplementedCommands();
|
||||
|
||||
Set<String> missingCommands = new HashSet<String>();
|
||||
for (String command : commands) {
|
||||
if (!implementedCommands.contains(command.trim())) {
|
||||
missingCommands.add(command);
|
||||
}
|
||||
}
|
||||
|
||||
if (!missingCommands.isEmpty()) {
|
||||
fail("There are missing commands: " + missingCommands.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> getImplementedCommands() {
|
||||
Method[] methods = Jedis.class.getDeclaredMethods();
|
||||
Set<String> implementedCommands = new HashSet<String>();
|
||||
for (Method method : methods) {
|
||||
implementedCommands.add(method.getName().trim().toLowerCase());
|
||||
}
|
||||
|
||||
methods = JedisPubSub.class.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
implementedCommands.add(method.getName().trim().toLowerCase());
|
||||
}
|
||||
|
||||
methods = Transaction.class.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
implementedCommands.add(method.getName().trim().toLowerCase());
|
||||
}
|
||||
implementedCommands.add("config");
|
||||
return implementedCommands;
|
||||
}
|
||||
|
||||
private String[] getAvailableCommands() throws MalformedURLException,
|
||||
IOException {
|
||||
URL url = new URL("http://dimaion.com/redis/master");
|
||||
InputStream openStream = url.openStream();
|
||||
DataInputStream dis = new DataInputStream(new BufferedInputStream(
|
||||
openStream));
|
||||
byte[] all = new byte[dis.available()];
|
||||
dis.readFully(all);
|
||||
String commandList = new String(all);
|
||||
String[] commands = commandList.split("\n");
|
||||
return commands;
|
||||
}
|
||||
}
|
||||
@@ -219,4 +219,20 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.select(1);
|
||||
assertEquals(0, jedis.dbSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void persist() {
|
||||
jedis.setex("foo", 60 * 60, "bar");
|
||||
assertTrue(jedis.ttl("foo") > 0);
|
||||
int status = jedis.persist("foo");
|
||||
assertEquals(1, status);
|
||||
assertEquals(-1, jedis.ttl("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void echo() {
|
||||
String result = jedis.echo("hello world");
|
||||
assertEquals("hello world", result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,8 +16,13 @@ public class ControlCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void bgsave() {
|
||||
String status = jedis.bgsave();
|
||||
assertEquals("Background saving started", status);
|
||||
try {
|
||||
String status = jedis.bgsave();
|
||||
assertEquals("Background saving started", status);
|
||||
} catch (JedisException e) {
|
||||
assertEquals("ERR background save already in progress", e
|
||||
.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,4 +77,10 @@ public class ControlCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals("OK", status);
|
||||
jedis.configSet("maxmemory", memory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sync() {
|
||||
jedis.sync();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -249,6 +249,25 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("foo", result.get(0));
|
||||
assertEquals("bar", result.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lpushx() {
|
||||
int status = jedis.lpushx("foo", "bar");
|
||||
assertEquals(0, status);
|
||||
|
||||
jedis.lpush("foo", "a");
|
||||
status = jedis.lpushx("foo", "b");
|
||||
assertEquals(2, status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpushx() {
|
||||
int status = jedis.rpushx("foo", "bar");
|
||||
assertEquals(0, status);
|
||||
|
||||
jedis.lpush("foo", "a");
|
||||
status = jedis.rpushx("foo", "b");
|
||||
assertEquals(2, status);
|
||||
}
|
||||
}
|
||||
@@ -169,4 +169,10 @@ public class StringValuesCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals("This is a string", jedis.substr("s", 0, -1));
|
||||
assertEquals(" string", jedis.substr("s", 9, 100000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void strlen() {
|
||||
jedis.set("s", "This is a string");
|
||||
assertEquals("This is a string".length(), jedis.strlen("s"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user