Support null sortParams in Lettuce and SRP sort
DATAREDIS-217
This commit is contained in:
@@ -101,6 +101,10 @@ abstract class LettuceUtils {
|
||||
static SortArgs sort(SortParameters params) {
|
||||
SortArgs args = new SortArgs();
|
||||
|
||||
if(params == null) {
|
||||
return args;
|
||||
}
|
||||
|
||||
if (params.getByPattern() != null) {
|
||||
args.by(new String(params.getByPattern(), Charsets.ASCII));
|
||||
}
|
||||
|
||||
@@ -223,34 +223,36 @@ abstract class SrpUtils {
|
||||
static Object[] sortParams(SortParameters params, byte[] sortKey) {
|
||||
List<byte[]> arrays = new ArrayList<byte[]>();
|
||||
|
||||
if (params.getByPattern() != null) {
|
||||
arrays.add(BY);
|
||||
arrays.add(params.getByPattern());
|
||||
}
|
||||
|
||||
if (params.getLimit() != null) {
|
||||
arrays.add(limit(params.getLimit().getStart(), params.getLimit().getCount()));
|
||||
}
|
||||
|
||||
if (params.getGetPattern() != null) {
|
||||
byte[][] pattern = params.getGetPattern();
|
||||
for (byte[] bs : pattern) {
|
||||
arrays.add(GET);
|
||||
arrays.add(bs);
|
||||
if(params != null) {
|
||||
if (params.getByPattern() != null) {
|
||||
arrays.add(BY);
|
||||
arrays.add(params.getByPattern());
|
||||
}
|
||||
}
|
||||
|
||||
if (params.getOrder() != null) {
|
||||
arrays.add(params.getOrder().name().getBytes(Charsets.UTF_8));
|
||||
}
|
||||
if (params.getLimit() != null) {
|
||||
arrays.add(limit(params.getLimit().getStart(), params.getLimit().getCount()));
|
||||
}
|
||||
|
||||
if (params.isAlphabetic()) {
|
||||
arrays.add(ALPHA);
|
||||
}
|
||||
if (params.getGetPattern() != null) {
|
||||
byte[][] pattern = params.getGetPattern();
|
||||
for (byte[] bs : pattern) {
|
||||
arrays.add(GET);
|
||||
arrays.add(bs);
|
||||
}
|
||||
}
|
||||
|
||||
if (sortKey != null) {
|
||||
arrays.add(STORE);
|
||||
arrays.add(sortKey);
|
||||
if (params.getOrder() != null) {
|
||||
arrays.add(params.getOrder().name().getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
if (params.isAlphabetic()) {
|
||||
arrays.add(ALPHA);
|
||||
}
|
||||
|
||||
if (sortKey != null) {
|
||||
arrays.add(STORE);
|
||||
arrays.add(sortKey);
|
||||
}
|
||||
}
|
||||
|
||||
return arrays.toArray();
|
||||
|
||||
@@ -449,6 +449,17 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
Arrays.asList(new String[] { "bar", "baz", "foo" }) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortNullParams() {
|
||||
actual.add(connection.rPush("sortlist", "5"));
|
||||
actual.add(connection.rPush("sortlist", "2"));
|
||||
actual.add(connection.rPush("sortlist", "3"));
|
||||
actual.add(connection.sort("sortlist", null));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 2l, 3l,
|
||||
Arrays.asList(new String[] { "2", "3", "5" }) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDbSize() {
|
||||
connection.set("dbparam", "foo");
|
||||
|
||||
@@ -83,6 +83,10 @@ public class JedisConnectionPipelineIntegrationTests extends
|
||||
public void testSortStore() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-143 Pipeline tries to return Long instead of List<String> on sort with no params")
|
||||
public void testSortNullParams() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-143 Jedis ClassCastExceptions closing pipeline on certain ops")
|
||||
public void testMultiExec() {
|
||||
}
|
||||
|
||||
@@ -295,6 +295,16 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
|
||||
connection.lRange("newlist", 0, 9));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortNullParams() {
|
||||
connection.rPush("sortlist", "5");
|
||||
connection.rPush("sortlist", "2");
|
||||
connection.rPush("sortlist", "3");
|
||||
actual.add(connection.sort("sortlist", null));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { Arrays.asList(new String[] { "2", "3", "5" }) }), actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLPop() {
|
||||
connection.rPush("PopList", "hello");
|
||||
|
||||
@@ -79,6 +79,10 @@ public class RjcConnectionIntegrationTests extends AbstractConnectionIntegration
|
||||
public void testSortStore() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-134 string ops do not work with encoded values")
|
||||
public void testSortNullParams() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-134 string ops do not work with encoded values")
|
||||
public void testGetRangeSetRange() {
|
||||
}
|
||||
|
||||
@@ -75,6 +75,10 @@ public class RjcConnectionPipelineIntegrationTests extends
|
||||
public void testSortStore() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-134 string ops do not work with encoded values")
|
||||
public void testSortNullParams() {
|
||||
}
|
||||
|
||||
@Ignore("DATAREDIS-134 string ops do not work with encoded values")
|
||||
public void testStrLen() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user