Implemented BLPOP
This commit is contained in:
@@ -11,7 +11,7 @@ Jedis is a WORK IN PROGRESS.
|
||||
- Publish/Subscribe
|
||||
- Persistence control commands
|
||||
- Remote server control commands
|
||||
- The AUTH, SORT, BLPOP, BRPOP, ZRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE commands
|
||||
- The AUTH, SORT, BRPOP, ZRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE commands
|
||||
|
||||
But stay close because things are going fast and all this will be implemented soon!
|
||||
|
||||
@@ -20,7 +20,7 @@ But stay close because things are going fast and all this will be implemented so
|
||||
- Commands operating on all the kind of values
|
||||
- Commands operating on string values
|
||||
- Commands operating on hashes
|
||||
- Commands operating on lists (not SORT, BLPOP, BRPOP)
|
||||
- Commands operating on lists (not SORT, BRPOP)
|
||||
- Commands operating on sets
|
||||
- Commands operating on sorted sets (not SORT, ZRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE)
|
||||
- Transactions
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>0.0.8</version>
|
||||
<version>0.0.9</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
||||
@@ -395,4 +395,8 @@ public class Client extends Connection {
|
||||
args.addAll(sortingParameters.getParams());
|
||||
sendCommand("SORT", args.toArray(new String[args.size()]));
|
||||
}
|
||||
|
||||
public void blpop(String[] args) throws JedisException {
|
||||
sendCommand("BLPOP", args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package redis.clients.jedis;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -428,7 +429,9 @@ public class Jedis {
|
||||
Set<Tuple> set = new LinkedHashSet<Tuple>();
|
||||
Iterator<String> iterator = membersWithScores.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
set.add(new Tuple(iterator.next(), Double.valueOf(iterator.next())));
|
||||
set
|
||||
.add(new Tuple(iterator.next(), Double.valueOf(iterator
|
||||
.next())));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
@@ -440,7 +443,9 @@ public class Jedis {
|
||||
Set<Tuple> set = new LinkedHashSet<Tuple>();
|
||||
Iterator<String> iterator = membersWithScores.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
set.add(new Tuple(iterator.next(), Double.valueOf(iterator.next())));
|
||||
set
|
||||
.add(new Tuple(iterator.next(), Double.valueOf(iterator
|
||||
.next())));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
@@ -503,4 +508,15 @@ public class Jedis {
|
||||
return client.getMultiBulkReply();
|
||||
}
|
||||
|
||||
}
|
||||
public List<String> blpop(int timeout, String... keys)
|
||||
throws JedisException {
|
||||
List<String> args = new ArrayList<String>();
|
||||
for (String arg : keys) {
|
||||
args.add(arg);
|
||||
}
|
||||
args.add(String.valueOf(timeout));
|
||||
|
||||
client.blpop(args.toArray(new String[args.size()]));
|
||||
return client.getMultiBulkReply();
|
||||
}
|
||||
}
|
||||
@@ -129,8 +129,11 @@ public class Protocol {
|
||||
}
|
||||
|
||||
private Object processMultiBulkReply(InputStream is) throws JedisException {
|
||||
List<Object> ret = new ArrayList<Object>();
|
||||
int num = Integer.parseInt(readLine(is));
|
||||
if (num == -1) {
|
||||
return null;
|
||||
}
|
||||
List<Object> ret = new ArrayList<Object>();
|
||||
for (int i = 0; i < num; i++) {
|
||||
ret.add(process(is));
|
||||
}
|
||||
|
||||
@@ -102,6 +102,15 @@ public class ProtocolTest extends Assert {
|
||||
expected2.add(sub);
|
||||
|
||||
assertEquals(expected2, response2);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void nullMultiBulkReply() throws JedisException {
|
||||
InputStream is = new ByteArrayInputStream("*-1\r\n".getBytes());
|
||||
Protocol protocol = new Protocol();
|
||||
List<String> response = (List<String>) (List<?>) protocol
|
||||
.getMultiBulkReply(is);
|
||||
assertNull(response);
|
||||
}
|
||||
}
|
||||
@@ -220,4 +220,26 @@ public class ListCommandsTest extends Assert {
|
||||
assertEquals(srcExpected, jedis.lrange("foo", 0, 1000));
|
||||
assertEquals(dstExpected, jedis.lrange("dst", 0, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blpop() throws JedisException {
|
||||
List<String> result = jedis.blpop(2, "foo");
|
||||
assertNull(result);
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Jedis j = new Jedis("localhost");
|
||||
j.connect();
|
||||
List<String> result = j.blpop(0, "foo");
|
||||
assertNotNull(result);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("bar", result.get(0));
|
||||
} catch (Exception ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
jedis.lpush("foo", "bar");
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class TransactionCommandsTest extends Assert {
|
||||
|
||||
t.set("mykey", val);
|
||||
List<Object> resp = t.exec();
|
||||
assertEquals(new ArrayList<Object>(), resp);
|
||||
assertEquals(null, resp);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user