Added support for nested lists, and longs in lists.
This commit is contained in:
@@ -2783,17 +2783,18 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Object getEvalResult() {
|
private Object getEvalResult() {
|
||||||
Object result = client.getOne();
|
return evalResult(client.getOne());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object evalResult(Object result) {
|
||||||
if (result instanceof byte[])
|
if (result instanceof byte[])
|
||||||
return SafeEncoder.encode((byte[]) result);
|
return SafeEncoder.encode((byte[]) result);
|
||||||
|
|
||||||
if (result instanceof List<?>) {
|
if (result instanceof List<?>) {
|
||||||
List<?> list = (List<?>) result;
|
List<?> list = (List<?>) result;
|
||||||
List<String> listResult = new ArrayList<String>(list.size());
|
List<Object> listResult = new ArrayList<Object>(list.size());
|
||||||
for (Object bin : list) {
|
for (Object bin : list) {
|
||||||
listResult.add((bin == null ? null : SafeEncoder
|
listResult.add(evalResult(bin));
|
||||||
.encode((byte[]) bin)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return listResult;
|
return listResult;
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
package redis.clients.jedis.tests.commands;
|
package redis.clients.jedis.tests.commands;
|
||||||
|
|
||||||
|
import org.hamcrest.CoreMatchers;
|
||||||
|
import org.hamcrest.core.CombinableMatcher;
|
||||||
|
import org.junit.Test;
|
||||||
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
|
import redis.clients.util.SafeEncoder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.hamcrest.CoreMatchers.both;
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import redis.clients.jedis.exceptions.JedisDataException;
|
import static org.hamcrest.CoreMatchers.hasItem;
|
||||||
import redis.clients.util.SafeEncoder;
|
|
||||||
|
|
||||||
public class ScriptingCommandsTest extends JedisCommandTestBase {
|
public class ScriptingCommandsTest extends JedisCommandTestBase {
|
||||||
|
|
||||||
@@ -57,6 +62,15 @@ public class ScriptingCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(new Long(2), response);
|
assertEquals(new Long(2), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void evalNestedLists() {
|
||||||
|
String script = "return { {KEYS[1]} , {2} }";
|
||||||
|
List<?> results = (List<?>) jedis.eval(script, 1, "key1");
|
||||||
|
|
||||||
|
assertThat((List<String>) results.get(0), listWithItem("key1"));
|
||||||
|
assertThat((List<Long>) results.get(1), listWithItem(2L));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void evalNoArgs() {
|
public void evalNoArgs() {
|
||||||
String script = "return KEYS[1]";
|
String script = "return KEYS[1]";
|
||||||
@@ -156,7 +170,10 @@ public class ScriptingCommandsTest extends JedisCommandTestBase {
|
|||||||
assertEquals(results.get(1), "key2");
|
assertEquals(results.get(1), "key2");
|
||||||
assertEquals(results.get(2), "1");
|
assertEquals(results.get(2), "1");
|
||||||
assertEquals(results.get(3), "2");
|
assertEquals(results.get(3), "2");
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> CombinableMatcher<List<T>> listWithItem(T expected) {
|
||||||
|
return both(CoreMatchers.<List<T>>instanceOf(List.class)).and(hasItem(equalTo(expected)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user