diff --git a/README.md b/README.md index e16978b..3deb7cc 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Jedis is a WORK IN PROGRESS. - Publish/Subscribe - Persistence control commands - Remote server control commands -- The AUTH, BRPOP, ZRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE commands +- The AUTH, 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 BRPOP) +- Commands operating on lists - Commands operating on sets - Commands operating on sorted sets (not ZRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE) - Transactions diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index 6ba24d7..b6403a1 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -413,4 +413,8 @@ public class Client extends Connection { public void sort(String key, String dstkey) throws JedisException { sendCommand("SORT", key, "STORE", dstkey); } + + public void brpop(String[] args) throws JedisException { + sendCommand("BRPOP", args); + } } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 653ea75..56902ac 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -530,4 +530,16 @@ public class Jedis { client.sort(key, dstkey); return client.getIntegerReply(); } + + public List brpop(int timeout, String... keys) + throws JedisException { + List args = new ArrayList(); + for (String arg : keys) { + args.add(arg); + } + args.add(String.valueOf(timeout)); + + client.brpop(args.toArray(new String[args.size()])); + return client.getMultiBulkReply(); + } } \ No newline at end of file diff --git a/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java index 4693583..543a7b8 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/ListCommandsTest.java @@ -242,4 +242,26 @@ public class ListCommandsTest extends Assert { }); jedis.lpush("foo", "bar"); } + + @Test + public void brpop() throws JedisException { + List result = jedis.brpop(2, "foo"); + assertNull(result); + + new Thread(new Runnable() { + public void run() { + try { + Jedis j = new Jedis("localhost"); + j.connect(); + List result = j.brpop(0, "foo"); + assertNotNull(result); + assertEquals(1, result.size()); + assertEquals("bar", result.get(0)); + } catch (Exception ex) { + fail(ex.getMessage()); + } + } + }); + jedis.lpush("foo", "bar"); + } } \ No newline at end of file