diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index a5323d2..e87ca29 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -715,6 +715,10 @@ public class BinaryClient extends Connection { sendCommand(SETBIT, key, toByteArray(offset), value); } + public void setbit(byte[] key, long offset, boolean value) { + sendCommand(SETBIT, key, toByteArray(offset), toByteArray(value)); + } + public void getbit(byte[] key, long offset) { sendCommand(GETBIT, key, toByteArray(offset)); } diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index fd537d3..16c90f1 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -135,6 +135,12 @@ public class BinaryJedis implements BinaryJedisCommands { return client.getIntegerReply(); } + public Long del(final byte[] key) { + checkIsInMulti(); + client.del(key); + return client.getIntegerReply(); + } + /** * Return the type of the value stored at key in form of a string. The type * can be one of "none", "string", "list", "set". "none" is returned if the @@ -989,7 +995,7 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Multi bulk reply, specifically a list of elements in the * specified range. */ - public List lrange(final byte[] key, final int start, final int end) { + public List lrange(final byte[] key, final long start, final long end) { checkIsInMulti(); client.lrange(key, start, end); return client.getBinaryMultiBulkReply(); @@ -1029,7 +1035,7 @@ public class BinaryJedis implements BinaryJedisCommands { * @param end * @return Status code reply */ - public String ltrim(final byte[] key, final int start, final int end) { + public String ltrim(final byte[] key, final long start, final long end) { checkIsInMulti(); client.ltrim(key, start, end); return client.getStatusCodeReply(); @@ -1053,7 +1059,7 @@ public class BinaryJedis implements BinaryJedisCommands { * @param index * @return Bulk reply, specifically the requested element */ - public byte[] lindex(final byte[] key, final int index) { + public byte[] lindex(final byte[] key, final long index) { checkIsInMulti(); client.lindex(key, index); return client.getBinaryBulkReply(); @@ -1080,7 +1086,7 @@ public class BinaryJedis implements BinaryJedisCommands { * @param value * @return Status code reply */ - public String lset(final byte[] key, final int index, final byte[] value) { + public String lset(final byte[] key, final long index, final byte[] value) { checkIsInMulti(); client.lset(key, index, value); return client.getStatusCodeReply(); @@ -1105,7 +1111,7 @@ public class BinaryJedis implements BinaryJedisCommands { * @return Integer Reply, specifically: The number of removed elements if * the operation succeeded */ - public Long lrem(final byte[] key, final int count, final byte[] value) { + public Long lrem(final byte[] key, final long count, final byte[] value) { checkIsInMulti(); client.lrem(key, count, value); return client.getIntegerReply(); @@ -1485,7 +1491,7 @@ public class BinaryJedis implements BinaryJedisCommands { return client.getIntegerReply(); } - public Set zrange(final byte[] key, final int start, final int end) { + public Set zrange(final byte[] key, final long start, final long end) { checkIsInMulti(); client.zrange(key, start, end); final List members = client.getBinaryMultiBulkReply(); @@ -1597,24 +1603,24 @@ public class BinaryJedis implements BinaryJedisCommands { return client.getIntegerReply(); } - public Set zrevrange(final byte[] key, final int start, - final int end) { + public Set zrevrange(final byte[] key, final long start, + final long end) { checkIsInMulti(); client.zrevrange(key, start, end); final List members = client.getBinaryMultiBulkReply(); return new LinkedHashSet(members); } - public Set zrangeWithScores(final byte[] key, final int start, - final int end) { + public Set zrangeWithScores(final byte[] key, final long start, + final long end) { checkIsInMulti(); client.zrangeWithScores(key, start, end); Set set = getBinaryTupledSet(); return set; } - public Set zrevrangeWithScores(final byte[] key, final int start, - final int end) { + public Set zrevrangeWithScores(final byte[] key, final long start, + final long end) { checkIsInMulti(); client.zrevrangeWithScores(key, start, end); Set set = getBinaryTupledSet(); @@ -2020,6 +2026,28 @@ public class BinaryJedis implements BinaryJedisCommands { return multiBulkReply; } + public List blpop(byte[] arg) { + checkIsInMulti(); + byte[][] args = new byte[1][]; + args[0] = arg; + client.blpop(args); + client.setTimeoutInfinite(); + final List multiBulkReply = client.getBinaryMultiBulkReply(); + client.rollbackTimeout(); + return multiBulkReply; + } + + public List brpop(byte[] arg) { + checkIsInMulti(); + byte[][] args = new byte[1][]; + args[0] = arg; + client.brpop(args); + client.setTimeoutInfinite(); + final List multiBulkReply = client.getBinaryMultiBulkReply(); + client.rollbackTimeout(); + return multiBulkReply; + } + /** * Request for authentication in a password protected Redis server. A Redis * server can be instructed to require a password before to allow clients to @@ -2448,7 +2476,7 @@ public class BinaryJedis implements BinaryJedisCommands { * operation * */ - public Long zremrangeByRank(final byte[] key, final int start, final int end) { + public Long zremrangeByRank(final byte[] key, final long start, final long end) { checkIsInMulti(); client.zremrangeByRank(key, start, end); return client.getIntegerReply(); @@ -3026,11 +3054,16 @@ public class BinaryJedis implements BinaryJedisCommands { * @param value * @return */ - public Boolean setbit(byte[] key, long offset, byte[] value) { + public Boolean setbit(byte[] key, long offset, boolean value) { client.setbit(key, offset, value); return client.getIntegerReply() == 1; } + public Boolean setbit(byte[] key, long offset, byte[] value) { + client.setbit(key, offset, value); + return client.getIntegerReply() == 1; + } + /** * Returns the bit value at offset in the string value stored at key * @@ -3048,9 +3081,9 @@ public class BinaryJedis implements BinaryJedisCommands { return client.getIntegerReply(); } - public String getrange(byte[] key, long startOffset, long endOffset) { + public byte[] getrange(byte[] key, long startOffset, long endOffset) { client.getrange(key, startOffset, endOffset); - return client.getBulkReply(); + return client.getBinaryBulkReply(); } public Long publish(byte[] channel, byte[] message) { diff --git a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java index 77189f7..237d584 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedisCommands.java +++ b/src/main/java/redis/clients/jedis/BinaryJedisCommands.java @@ -17,6 +17,8 @@ public interface BinaryJedisCommands { Boolean exists(byte[] key); + Long persist(byte[] key); + String type(byte[] key); Long expire(byte[] key, int seconds); @@ -25,6 +27,16 @@ public interface BinaryJedisCommands { Long ttl(byte[] key); + Boolean setbit(byte[] key, long offset, boolean value); + + Boolean setbit(byte[] key, long offset, byte[] value); + + Boolean getbit(byte[] key, long offset); + + Long setrange(byte[] key, long offset, byte[] value); + + byte[] getrange(byte[] key, long startOffset, long endOffset); + byte[] getSet(byte[] key, byte[] value); Long setnx(byte[] key, byte[] value); @@ -67,21 +79,21 @@ public interface BinaryJedisCommands { Map hgetAll(byte[] key); - Long rpush(byte[] key, byte[]... string); + Long rpush(byte[] key, byte[]... args); - Long lpush(byte[] key, byte[]... string); + Long lpush(byte[] key, byte[]... args); Long llen(byte[] key); - List lrange(byte[] key, int start, int end); + List lrange(byte[] key, long start, long end); - String ltrim(byte[] key, int start, int end); + String ltrim(byte[] key, long start, long end); - byte[] lindex(byte[] key, int index); + byte[] lindex(byte[] key, long index); - String lset(byte[] key, int index, byte[] value); + String lset(byte[] key, long index, byte[] value); - Long lrem(byte[] key, int count, byte[] value); + Long lrem(byte[] key, long count, byte[] value); byte[] lpop(byte[] key); @@ -101,11 +113,13 @@ public interface BinaryJedisCommands { byte[] srandmember(byte[] key); - Long zadd(byte[] key, double score, byte[] member); + Long strlen(byte[] key); + Long zadd(byte[] key, double score, byte[] member); + Long zadd(byte[] key, Map scoreMembers); - Set zrange(byte[] key, int start, int end); + Set zrange(byte[] key, long start, long end); Long zrem(byte[] key, byte[]... member); @@ -115,11 +129,11 @@ public interface BinaryJedisCommands { Long zrevrank(byte[] key, byte[] member); - Set zrevrange(byte[] key, int start, int end); + Set zrevrange(byte[] key, long start, long end); - Set zrangeWithScores(byte[] key, int start, int end); + Set zrangeWithScores(byte[] key, long start, long end); - Set zrevrangeWithScores(byte[] key, int start, int end); + Set zrevrangeWithScores(byte[] key, long start, long end); Long zcard(byte[] key); @@ -135,54 +149,62 @@ public interface BinaryJedisCommands { Set zrangeByScore(byte[] key, double min, double max); + Set zrevrangeByScore(byte[] key, double max, double min); + Set zrangeByScore(byte[] key, double min, double max, int offset, int count); - Set zrangeByScoreWithScores(byte[] key, double min, double max); - - Set zrangeByScoreWithScores(byte[] key, double min, double max, - int offset, int count); - - Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max); - - Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, - int offset, int count); - - Set zrevrangeByScore(byte[] key, double max, double min); - - Set zrevrangeByScore(byte[] key, double max, double min, - int offset, int count); - Set zrevrangeByScore(byte[] key, byte[] max, byte[] min); - Set zrevrangeByScore(byte[] key, byte[] max, byte[] min, - int offset, int count); + Set zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, + int count); + + Set zrevrangeByScore(byte[] key, double max, double min, + int offset, int count); + + Set zrangeByScoreWithScores(byte[] key, double min, double max); Set zrevrangeByScoreWithScores(byte[] key, double max, double min); - Set zrevrangeByScoreWithScores(byte[] key, double max, double min, - int offset, int count); + Set zrangeByScoreWithScores(byte[] key, double min, double max, + int offset, int count); + + Set zrevrangeByScore(byte[] key, byte[] max, byte[] min, + int offset, int count); + Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max); + Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min); - Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, - int offset, int count); + Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, + int offset, int count); - Long zremrangeByRank(byte[] key, int start, int end); + Set zrevrangeByScoreWithScores(byte[] key, double max, double min, + int offset, int count); + + Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, + int offset, int count); + + Long zremrangeByRank(byte[] key, long start, long end); Long zremrangeByScore(byte[] key, double start, double end); - + Long zremrangeByScore(byte[] key, byte[] start, byte[] end); - Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value); + Long linsert(byte[] key, Client.LIST_POSITION where, byte[] pivot, + byte[] value); + + Long lpushx(byte[] key, byte[] arg); + + Long rpushx(byte[] key, byte[] arg); - Long objectRefcount(byte[] key); + List blpop(byte[] arg); - Long objectIdletime(byte[] key); + List brpop(byte[] arg); - byte[] objectEncoding(byte[] key); + Long del(byte[] key); - Long lpushx(byte[] key, byte[] string); + byte[] echo(byte[] arg); - Long rpushx(byte[] key, byte[] string); + Long move(byte[] key, int dbIndex); } diff --git a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java index 68adb8d..9e9d72b 100644 --- a/src/main/java/redis/clients/jedis/BinaryShardedJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryShardedJedis.java @@ -220,27 +220,27 @@ public class BinaryShardedJedis extends Sharded return j.llen(key); } - public List lrange(byte[] key, int start, int end) { + public List lrange(byte[] key, long start, long end) { Jedis j = getShard(key); return j.lrange(key, start, end); } - public String ltrim(byte[] key, int start, int end) { + public String ltrim(byte[] key, long start, long end) { Jedis j = getShard(key); return j.ltrim(key, start, end); } - public byte[] lindex(byte[] key, int index) { + public byte[] lindex(byte[] key, long index) { Jedis j = getShard(key); return j.lindex(key, index); } - public String lset(byte[] key, int index, byte[] value) { + public String lset(byte[] key, long index, byte[] value) { Jedis j = getShard(key); return j.lset(key, index, value); } - public Long lrem(byte[] key, int count, byte[] value) { + public Long lrem(byte[] key, long count, byte[] value) { Jedis j = getShard(key); return j.lrem(key, count, value); } @@ -300,7 +300,7 @@ public class BinaryShardedJedis extends Sharded return j.zadd(key, scoreMembers); } - public Set zrange(byte[] key, int start, int end) { + public Set zrange(byte[] key, long start, long end) { Jedis j = getShard(key); return j.zrange(key, start, end); } @@ -325,17 +325,17 @@ public class BinaryShardedJedis extends Sharded return j.zrevrank(key, member); } - public Set zrevrange(byte[] key, int start, int end) { + public Set zrevrange(byte[] key, long start, long end) { Jedis j = getShard(key); return j.zrevrange(key, start, end); } - public Set zrangeWithScores(byte[] key, int start, int end) { + public Set zrangeWithScores(byte[] key, long start, long end) { Jedis j = getShard(key); return j.zrangeWithScores(key, start, end); } - public Set zrevrangeWithScores(byte[] key, int start, int end) { + public Set zrevrangeWithScores(byte[] key, long start, long end) { Jedis j = getShard(key); return j.zrevrangeWithScores(key, start, end); } @@ -404,6 +404,11 @@ public class BinaryShardedJedis extends Sharded return j.zrangeByScoreWithScores(key, min, max, offset, count); } + public Set zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count) { + Jedis j = getShard(key); + return j.zrangeByScore(key, min, max, offset, count); + } + public Set zrevrangeByScore(byte[] key, double max, double min) { Jedis j = getShard(key); return j.zrevrangeByScore(key, max, min); @@ -450,7 +455,7 @@ public class BinaryShardedJedis extends Sharded return j.zrevrangeByScoreWithScores(key, max, min, offset, count); } - public Long zremrangeByRank(byte[] key, int start, int end) { + public Long zremrangeByRank(byte[] key, long start, long end) { Jedis j = getShard(key); return j.zremrangeByRank(key, start, end); } @@ -499,6 +504,11 @@ public class BinaryShardedJedis extends Sharded return j.objectIdletime(key); } + public Boolean setbit(byte[] key, long offset, boolean value) { + Jedis j = getShard(key); + return j.setbit(key, offset, value); + } + public Boolean setbit(byte[] key, long offset, byte[] value) { Jedis j = getShard(key); return j.setbit(key, offset, value); @@ -514,8 +524,30 @@ public class BinaryShardedJedis extends Sharded return j.setrange(key, offset, value); } - public String getrange(byte[] key, long startOffset, long endOffset) { + public byte[] getrange(byte[] key, long startOffset, long endOffset) { Jedis j = getShard(key); return j.getrange(key, startOffset, endOffset); } + + public Long move(byte[] key, int dbIndex) { + Jedis j = getShard(key); + return j.move(key, dbIndex); + } + + public byte[] echo(byte[] arg) { + Jedis j = getShard(arg); + return j.echo(arg); + } + + public List brpop(byte[] arg) { + Jedis j = getShard(arg); + return j.brpop(arg); + } + + public List blpop(byte[] arg) { + Jedis j = getShard(arg); + return j.blpop(arg); + } + + } \ No newline at end of file diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index 39aae12..dd1b12b 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -592,7 +592,11 @@ public class Client extends BinaryClient implements Commands { } public void setbit(final String key, final long offset, final boolean value) { - setbit(SafeEncoder.encode(key), offset, toByteArray(value ? 1 : 0)); + setbit(SafeEncoder.encode(key), offset, value); + } + + public void setbit(final String key, final long offset, final String value) { + setbit(SafeEncoder.encode(key), offset, SafeEncoder.encode(value)); } public void getbit(String key, long offset) { diff --git a/src/main/java/redis/clients/jedis/Commands.java b/src/main/java/redis/clients/jedis/Commands.java index 7881909..0023158 100644 --- a/src/main/java/redis/clients/jedis/Commands.java +++ b/src/main/java/redis/clients/jedis/Commands.java @@ -30,6 +30,8 @@ public interface Commands { public void setbit(String key, long offset, boolean value); + public void setbit(String key, long offset, String value); + public void getbit(String key, long offset); public void setrange(String key, long offset, String value); diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index 8c91669..d61656e 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -2605,6 +2605,11 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand return client.getIntegerReply() == 1; } + public Boolean setbit(String key, long offset, String value) { + client.setbit(key, offset, value); + return client.getIntegerReply() == 1; + } + /** * Returns the bit value at offset in the string value stored at key * diff --git a/src/main/java/redis/clients/jedis/JedisCommands.java b/src/main/java/redis/clients/jedis/JedisCommands.java index 842e03f..54fdb77 100644 --- a/src/main/java/redis/clients/jedis/JedisCommands.java +++ b/src/main/java/redis/clients/jedis/JedisCommands.java @@ -26,6 +26,8 @@ public interface JedisCommands { Boolean setbit(String key, long offset, boolean value); + Boolean setbit(String key, long offset, String value); + Boolean getbit(String key, long offset); Long setrange(String key, long offset, String value); diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index b1e391d..e3126db 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -131,6 +131,10 @@ public final class Protocol { return process(is); } + public static final byte[] toByteArray(final boolean value) { + return toByteArray(value ? 1 : 0); + } + public static final byte[] toByteArray(final int value) { return SafeEncoder.encode(String.valueOf(value)); } diff --git a/src/main/java/redis/clients/jedis/ShardedJedis.java b/src/main/java/redis/clients/jedis/ShardedJedis.java index 6df9157..cb5b122 100644 --- a/src/main/java/redis/clients/jedis/ShardedJedis.java +++ b/src/main/java/redis/clients/jedis/ShardedJedis.java @@ -78,6 +78,11 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands { return j.setbit(key, offset, value); } + public Boolean setbit(String key, long offset, String value) { + Jedis j = getShard(key); + return j.setbit(key, offset, value); + } + public Boolean getbit(String key, long offset) { Jedis j = getShard(key); return j.getbit(key, offset);