Partial support for sorting
This commit is contained in:
15
pom.xml
15
pom.xml
@@ -12,4 +12,17 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>2.0.2</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.6</source>
|
||||||
|
<target>1.6</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
|
|||||||
@@ -340,8 +340,8 @@ public class Client extends Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void zrevrange(String key, int start, int end) throws JedisException {
|
public void zrevrange(String key, int start, int end) throws JedisException {
|
||||||
sendCommand("ZREVRANGE", key, String.valueOf(start), String
|
sendCommand("ZREVRANGE", key, String.valueOf(start),
|
||||||
.valueOf(end));
|
String.valueOf(end));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zrangeWithScores(String key, int start, int end)
|
public void zrangeWithScores(String key, int start, int end)
|
||||||
@@ -352,8 +352,8 @@ public class Client extends Connection {
|
|||||||
|
|
||||||
public void zrevrangeWithScores(String key, int start, int end)
|
public void zrevrangeWithScores(String key, int start, int end)
|
||||||
throws JedisException {
|
throws JedisException {
|
||||||
sendCommand("ZREVRANGE", key, String.valueOf(start), String
|
sendCommand("ZREVRANGE", key, String.valueOf(start),
|
||||||
.valueOf(end), "WITHSCORES");
|
String.valueOf(end), "WITHSCORES");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zcard(String key) throws JedisException {
|
public void zcard(String key) throws JedisException {
|
||||||
@@ -383,4 +383,13 @@ public class Client extends Connection {
|
|||||||
public void unwatch() throws JedisException {
|
public void unwatch() throws JedisException {
|
||||||
sendCommand("UNWATCH");
|
sendCommand("UNWATCH");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void sort(String key) throws JedisException {
|
||||||
|
sendCommand("SORT", key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sort(String key, SortingParams sortingParameters)
|
||||||
|
throws JedisException {
|
||||||
|
sendCommand("SORT", sortingParameters.getParams());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -428,9 +428,7 @@ public class Jedis {
|
|||||||
Set<Tuple> set = new LinkedHashSet<Tuple>();
|
Set<Tuple> set = new LinkedHashSet<Tuple>();
|
||||||
Iterator<String> iterator = membersWithScores.iterator();
|
Iterator<String> iterator = membersWithScores.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
set
|
set.add(new Tuple(iterator.next(), Double.valueOf(iterator.next())));
|
||||||
.add(new Tuple(iterator.next(), Double.valueOf(iterator
|
|
||||||
.next())));
|
|
||||||
}
|
}
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
@@ -442,9 +440,7 @@ public class Jedis {
|
|||||||
Set<Tuple> set = new LinkedHashSet<Tuple>();
|
Set<Tuple> set = new LinkedHashSet<Tuple>();
|
||||||
Iterator<String> iterator = membersWithScores.iterator();
|
Iterator<String> iterator = membersWithScores.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
set
|
set.add(new Tuple(iterator.next(), Double.valueOf(iterator.next())));
|
||||||
.add(new Tuple(iterator.next(), Double.valueOf(iterator
|
|
||||||
.next())));
|
|
||||||
}
|
}
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
@@ -496,4 +492,15 @@ public class Jedis {
|
|||||||
return client.getStatusCodeReply();
|
return client.getStatusCodeReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> sort(String key) throws JedisException {
|
||||||
|
client.sort(key);
|
||||||
|
return client.getMultiBulkReply();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> sort(String key, SortingParams sortingParameters)
|
||||||
|
throws JedisException {
|
||||||
|
client.sort(key, sortingParameters);
|
||||||
|
return client.getMultiBulkReply();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
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