Partial support for sorting
This commit is contained in:
20
src/test/java/redis/clients/jedis/SortingParams.java
Normal file
20
src/test/java/redis/clients/jedis/SortingParams.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SortingParams {
|
||||
private String pattern = null;
|
||||
private List<String> params = new ArrayList<String>();
|
||||
|
||||
public SortingParams by(String pattern) {
|
||||
this.pattern = pattern;
|
||||
params.add("BY");
|
||||
params.add(pattern);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String[] getParams() {
|
||||
return params.toArray(new String[params.size()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisException;
|
||||
import redis.clients.jedis.SortingParams;
|
||||
|
||||
public class SortingCommandsTest extends Assert {
|
||||
private Jedis jedis;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
jedis = new Jedis("localhost");
|
||||
jedis.connect();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
jedis.flushDB();
|
||||
jedis.disconnect();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sort() throws JedisException {
|
||||
jedis.lpush("foo", "3");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "1");
|
||||
|
||||
List<String> result = jedis.sort("foo");
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("1");
|
||||
expected.add("2");
|
||||
expected.add("3");
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortBy() throws JedisException {
|
||||
jedis.lpush("foo", "3");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "1");
|
||||
|
||||
SortingParams sp = new SortingParams();
|
||||
sp.by("bar_*");
|
||||
|
||||
List<String> result = jedis.sort("foo", sp);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("foo_1");
|
||||
expected.add("foo_2");
|
||||
expected.add("foo_3");
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user