Implemented all the sorting parameters
This commit is contained in:
@@ -399,4 +399,18 @@ public class Client extends Connection {
|
||||
public void blpop(String[] args) throws JedisException {
|
||||
sendCommand("BLPOP", args);
|
||||
}
|
||||
|
||||
public void sort(String key, SortingParams sortingParameters, String dstkey)
|
||||
throws JedisException {
|
||||
List<String> args = new ArrayList<String>();
|
||||
args.add(key);
|
||||
args.addAll(sortingParameters.getParams());
|
||||
args.add("STORE");
|
||||
args.add(dstkey);
|
||||
sendCommand("SORT", args.toArray(new String[args.size()]));
|
||||
}
|
||||
|
||||
public void sort(String key, String dstkey) throws JedisException {
|
||||
sendCommand("SORT", key, "STORE", dstkey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,4 +519,15 @@ public class Jedis {
|
||||
client.blpop(args.toArray(new String[args.size()]));
|
||||
return client.getMultiBulkReply();
|
||||
}
|
||||
|
||||
public int sort(String key, SortingParams sortingParameters, String dstkey)
|
||||
throws JedisException {
|
||||
client.sort(key, sortingParameters, dstkey);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
|
||||
public int sort(String key, String dstkey) throws JedisException {
|
||||
client.sort(key, dstkey);
|
||||
return client.getIntegerReply();
|
||||
}
|
||||
}
|
||||
@@ -39,4 +39,12 @@ public class SortingParams {
|
||||
params.add("ALPHA");
|
||||
return this;
|
||||
}
|
||||
|
||||
public SortingParams get(String... patterns) {
|
||||
for (String pattern : patterns) {
|
||||
params.add("GET");
|
||||
params.add(pattern);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -124,4 +124,52 @@ public class SortingCommandsTest extends Assert {
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortGet() throws JedisException {
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "10");
|
||||
|
||||
jedis.set("bar1", "bar1");
|
||||
jedis.set("bar2", "bar2");
|
||||
jedis.set("bar10", "bar10");
|
||||
|
||||
jedis.set("car1", "car1");
|
||||
jedis.set("car2", "car2");
|
||||
jedis.set("car10", "car10");
|
||||
|
||||
SortingParams sp = new SortingParams();
|
||||
sp.get("car*", "bar*");
|
||||
|
||||
List<String> result = jedis.sort("foo", sp);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("car1");
|
||||
expected.add("bar1");
|
||||
expected.add("car2");
|
||||
expected.add("bar2");
|
||||
expected.add("car10");
|
||||
expected.add("bar10");
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortStore() throws JedisException {
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "10");
|
||||
|
||||
int result = jedis.sort("foo", "result");
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("1");
|
||||
expected.add("2");
|
||||
expected.add("10");
|
||||
|
||||
assertEquals(3, result);
|
||||
assertEquals(expected, jedis.lrange("result", 0, 1000));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user