diff --git a/src/main/java/redis/clients/jedis/BinaryClient.java b/src/main/java/redis/clients/jedis/BinaryClient.java index 3383848..8af1981 100644 --- a/src/main/java/redis/clients/jedis/BinaryClient.java +++ b/src/main/java/redis/clients/jedis/BinaryClient.java @@ -877,11 +877,51 @@ public class BinaryClient extends Connection { sendCommand(PEXPIRE, key, toByteArray(milliseconds)); } - public void pexpireAt(final byte[] key, long millisecondsTimestamp) { + public void pexpireAt(final byte[] key, final long millisecondsTimestamp) { sendCommand(PEXPIREAT, key, toByteArray(millisecondsTimestamp)); } public void pttl(final byte[] key) { sendCommand(PTTL, key); } + + public void incrByFloat(final byte[] key, final double increment) { + sendCommand(INCRBYFLOAT, key, toByteArray(increment)); + } + + public void psetex(final byte[] key, final int milliseconds, final byte[] value) { + sendCommand(PSETEX, key, toByteArray(milliseconds), value); + } + + public void set(final byte[] key, final byte[] value, final byte[] nxxx) { + sendCommand(Command.SET, key, value, nxxx); + } + + public void set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final long time) { + sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time)); + } + + public void srandmember(final byte[] key, final int count) { + sendCommand(SRANDMEMBER, key, toByteArray(count)); + } + + public void clientKill(final byte[] client) { + sendCommand(CLIENT_KILL, client); + } + + public void clientGetname() { + sendCommand(CLIENT_GETNAME); + } + + public void clientList() { + sendCommand(CLIENT_LIST); + } + + public void clientSetname(final byte[] name) { + sendCommand(CLIENT_SETNAME); + } + + public void time() { + sendCommand(TIME); + } } diff --git a/src/main/java/redis/clients/jedis/BinaryJedis.java b/src/main/java/redis/clients/jedis/BinaryJedis.java index 465f118..e0e8689 100644 --- a/src/main/java/redis/clients/jedis/BinaryJedis.java +++ b/src/main/java/redis/clients/jedis/BinaryJedis.java @@ -1457,6 +1457,12 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey client.srandmember(key); return client.getBinaryBulkReply(); } + + public List srandmember(final byte[] key, final int count) { + checkIsInMulti(); + client.srandmember(key, count); + return client.getBinaryMultiBulkReply(); + } /** * Add the specified member having the specifeid score to the sorted set @@ -3268,4 +3274,60 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey client.pttl(key); return client.getIntegerReply(); } + + public Double incrByFloat(final byte[] key, final double increment) { + checkIsInMulti(); + client.incrByFloat(key, increment); + String relpy = client.getBulkReply(); + return (relpy != null ? new Double(relpy) : null); + } + + public String psetex(final byte[] key, final int milliseconds, final byte[] value) { + checkIsInMulti(); + client.psetex(key, milliseconds, value); + return client.getStatusCodeReply(); + } + + public String set(final byte[] key, final byte[] value, final byte[] nxxx) { + checkIsInMulti(); + client.set(key, value, nxxx); + return client.getStatusCodeReply(); + } + + public String set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final long time) { + checkIsInMulti(); + client.set(key, value, nxxx, expx, time); + return client.getStatusCodeReply(); + } + + public String clientKill(final byte[] client) { + checkIsInMulti(); + this.client.clientKill(client); + return this.client.getStatusCodeReply(); + } + + public String clientGetname() { + checkIsInMulti(); + client.clientGetname(); + return client.getBulkReply(); + } + + public String clientList() { + checkIsInMulti(); + client.clientList(); + return client.getBulkReply(); + } + + public String clientSetname(final byte[] name) { + checkIsInMulti(); + client.clientSetname(name); + return client.getBulkReply(); + } + + public List time() { + checkIsInMulti(); + client.time(); + return client.getMultiBulkReply(); + } + } diff --git a/src/main/java/redis/clients/jedis/Client.java b/src/main/java/redis/clients/jedis/Client.java index a268158..b6bceed 100644 --- a/src/main/java/redis/clients/jedis/Client.java +++ b/src/main/java/redis/clients/jedis/Client.java @@ -752,5 +752,32 @@ public class Client extends BinaryClient implements Commands { public void pttl(final String key) { pttl(SafeEncoder.encode(key)); } + + public void incrByFloat(final String key, final double increment) { + incrByFloat(SafeEncoder.encode(key), increment); + } + + public void psetex(final String key, final int milliseconds, final String value) { + psetex(SafeEncoder.encode(key), milliseconds, SafeEncoder.encode(value)); + } + + public void set(final String key, final String value, final String nxxx) { + set(SafeEncoder.encode(key), SafeEncoder.encode(value), SafeEncoder.encode(nxxx)); + } + + public void set(final String key, final String value, final String nxxx, final String expx, final long time) { + set(SafeEncoder.encode(key), SafeEncoder.encode(value), SafeEncoder.encode(nxxx), SafeEncoder.encode(expx), time); + } + + public void srandmember(final String key, final int count) { + srandmember(SafeEncoder.encode(key), count); + } + public void clientKill(final String client) { + clientKill(SafeEncoder.encode(client)); + } + + public void clientSetname(final String name) { + clientSetname(SafeEncoder.encode(name)); + } } diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java index fe0f7ab..22c02cc 100644 --- a/src/main/java/redis/clients/jedis/Jedis.java +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -1362,6 +1362,12 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand client.srandmember(key); return client.getBulkReply(); } + + public List srandmember(final String key, final int count) { + checkIsInMulti(); + client.srandmember(key); + return client.getMultiBulkReply(); + } /** * Add the specified member having the specifeid score to the sorted set @@ -3031,4 +3037,41 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand client.pttl(key); return client.getIntegerReply(); } + + public Double incrByFloat(final String key, final double increment) { + checkIsInMulti(); + client.incrByFloat(key, increment); + String relpy = client.getBulkReply(); + return (relpy != null ? new Double(relpy) : null); + } + + public String psetex(final String key, final int milliseconds, final String value) { + checkIsInMulti(); + client.psetex(key, milliseconds, value); + return client.getStatusCodeReply(); + } + + public String set(final String key, final String value, final String nxxx) { + checkIsInMulti(); + client.set(key, value, nxxx); + return client.getStatusCodeReply(); + } + + public String set(final String key, final String value, final String nxxx, final String expx, final long time) { + checkIsInMulti(); + client.set(key, value, nxxx, expx, time); + return client.getStatusCodeReply(); + } + + public String clientKill(final String client) { + checkIsInMulti(); + this.client.clientKill(client); + return this.client.getStatusCodeReply(); + } + + public String clientSetname(final String name) { + checkIsInMulti(); + client.clientSetname(name); + return client.getBulkReply(); + } } diff --git a/src/main/java/redis/clients/jedis/Protocol.java b/src/main/java/redis/clients/jedis/Protocol.java index b074a33..08b5193 100644 --- a/src/main/java/redis/clients/jedis/Protocol.java +++ b/src/main/java/redis/clients/jedis/Protocol.java @@ -155,7 +155,7 @@ public final class Protocol { public static enum Command { PING, SET, GET, QUIT, EXISTS, DEL, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME, RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX, SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET, HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, RPUSH, LPUSH, LLEN, LRANGE, LTRIM, LINDEX, LSET, LREM, LPOP, RPOP, RPOPLPUSH, SADD, SMEMBERS, SREM, SPOP, SMOVE, SCARD, SISMEMBER, SINTER, SINTERSTORE, SUNION, SUNIONSTORE, SDIFF, SDIFFSTORE, SRANDMEMBER, ZADD, ZRANGE, ZREM, ZINCRBY, ZRANK, ZREVRANK, ZREVRANGE, ZCARD, ZSCORE, MULTI, DISCARD, EXEC, WATCH, UNWATCH, SORT, BLPOP, BRPOP, AUTH, SUBSCRIBE, PUBLISH, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, ZCOUNT, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZUNIONSTORE, ZINTERSTORE, SAVE, BGSAVE, BGREWRITEAOF, LASTSAVE, SHUTDOWN, INFO, MONITOR, SLAVEOF, CONFIG, STRLEN, SYNC, LPUSHX, PERSIST, RPUSHX, ECHO, LINSERT, DEBUG, BRPOPLPUSH, SETBIT, GETBIT, SETRANGE, GETRANGE, EVAL, EVALSHA, SCRIPT, SLOWLOG, OBJECT, BITCOUNT, BITOP, SENTINEL, - DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL; + DUMP, RESTORE, PEXPIRE, PEXPIREAT, PTTL, INCRBYFLOAT, PSETEX, CLIENT_KILL, CLIENT_GETNAME, CLIENT_SETNAME, CLIENT_LIST, TIME; public final byte[] raw; diff --git a/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java b/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java index df10cb5..c88b388 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java +++ b/src/test/java/redis/clients/jedis/tests/commands/JedisCommandTestBase.java @@ -27,11 +27,7 @@ public abstract class JedisCommandTestBase extends JedisTestBase { public void setUp() throws Exception { jedis = new Jedis(hnp.host, hnp.port, 500); jedis.connect(); - try { jedis.auth("foobared"); - } catch (Exception e) { - // ignore - } jedis.configSet("timeout", "300"); jedis.flushAll(); } diff --git a/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java index fcf9f99..e34eb7b 100644 --- a/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java +++ b/src/test/java/redis/clients/jedis/tests/commands/StringValuesCommandsTest.java @@ -190,4 +190,20 @@ public class StringValuesCommandsTest extends JedisCommandTestBase { long value = jedis.incr("foo"); assertEquals(Long.MIN_VALUE, value); } + + @Test + public void incrByFloat() { + double value = jedis.incrByFloat("foo", 10.5); + assertEquals(10.5, value, 0.0); + value = jedis.incrByFloat("foo", 0.1); + assertEquals(10.6, value, 0.0); + } + + @Test + public void psetex() { + String status = jedis.psetex("foo", 20000, "bar"); + assertEquals("OK", status); + long ttl = jedis.ttl("foo"); + assertTrue(ttl > 0 && ttl <= 20000); + } } \ No newline at end of file