Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add new commands from redis 2.6

  • Loading branch information...
commit b305a52832d110353ddd53544ca0893900af446a 1 parent 1ad7213
@wg authored
View
9 README
@@ -1,9 +1,10 @@
lettuce - A scalable Java Redis client
- Lettuce is a scalable thread-safe Redis client. Multiple threads may share one
- RedisConnection provided they avoid blocking and transactional operations such
- as BLPOP, and MULTI/EXEC. Multiple connections are efficiently managed by the
- excellent netty NIO framework.
+ Lettuce is a scalable thread-safe Redis client providing both synchronous and
+ asyncronous connections. Multiple threads may share one connection provided
+ they avoid blocking and transactional operations such as BLPOP, and MULTI/EXEC.
+ Multiple connections are efficiently managed by the excellent netty NIO
+ framework.
This version of lettuce has been tested against redis 2.4.7
View
35 src/main/java/com/lambdaworks/redis/RedisAsyncConnection.java
@@ -225,6 +225,11 @@ public String auth(String password) {
return dispatch(HINCRBY, new IntegerOutput<K, V>(codec), args);
}
+ public Future<Double> hincrbyfloat(K key, K field, double amount) {
+ CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(key).addKey(field).add(amount);
+ return dispatch(HINCRBYFLOAT, new DoubleOutput<K, V>(codec), args);
+ }
+
public Future<Map<K, V>> hgetall(K key) {
return dispatch(HGETALL, new MapOutput<K, V>(codec), key);
}
@@ -270,6 +275,11 @@ public String auth(String password) {
return dispatch(INCRBY, new IntegerOutput<K, V>(codec), args);
}
+ public Future<Double> incrbyfloat(K key, double amount) {
+ CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(key).add(amount);
+ return dispatch(INCRBYFLOAT, new DoubleOutput<K, V>(codec), args);
+ }
+
public Future<String> info() {
return dispatch(INFO, new StatusOutput<K, V>(codec));
}
@@ -374,10 +384,29 @@ public String auth(String password) {
return dispatch(PERSIST, new BooleanOutput<K, V>(codec), key);
}
+ public Future<Boolean> pexpire(K key, long milliseconds) {
+ CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(key).add(milliseconds);
+ return dispatch(PEXPIRE, new BooleanOutput<K, V>(codec), args);
+ }
+
+ public Future<Boolean> pexpireat(K key, Date timestamp) {
+ return pexpireat(key, timestamp.getTime());
+ }
+
+ public Future<Boolean> pexpireat(K key, long timestamp) {
+ CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(key).add(timestamp);
+ return dispatch(PEXPIREAT, new BooleanOutput<K, V>(codec), args);
+ }
+
public Future<String> ping() {
return dispatch(PING, new StatusOutput<K, V>(codec));
}
+ public Future<Long> pttl(K key) {
+ CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(key);
+ return dispatch(PTTL, new IntegerOutput<K, V>(codec), args);
+ }
+
public Future<Long> publish(K channel, V message) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKey(channel).addValue(message);
return dispatch(PUBLISH, new IntegerOutput<K, V>(codec), args);
@@ -471,10 +500,16 @@ public String select(int db) {
return dispatch(SETRANGE, new IntegerOutput<K, V>(codec), args);
}
+ @Deprecated
public void shutdown() {
dispatch(SHUTDOWN, new StatusOutput<K, V>(codec));
}
+ public void shutdown(boolean save) {
+ CommandArgs<K, V> args = new CommandArgs<K, V>(codec);
+ dispatch(SHUTDOWN, new StatusOutput<K, V>(codec), save ? args.add(SAVE) : args.add(NOSAVE));
+ }
+
public Future<Set<V>> sinter(K... keys) {
CommandArgs<K, V> args = new CommandArgs<K, V>(codec).addKeys(keys);
return dispatch(SINTER, new ValueSetOutput<K, V>(codec), args);
View
4 src/main/java/com/lambdaworks/redis/RedisClient.java
@@ -21,8 +21,8 @@
/**
* A scalable thread-safe <a href="http://redis.io/">Redis</a> client. Multiple threads
- * may share one {@link RedisAsyncConnection} provided they avoid blocking and transactional
- * operations such as BLPOP and MULTI/EXEC.
+ * may share one connection provided they avoid blocking and transactional operations
+ * such as BLPOP and MULTI/EXEC.
*
* @author Will Glozer
*/
View
30 src/main/java/com/lambdaworks/redis/RedisConnection.java
@@ -191,6 +191,10 @@ public Long hincrby(K key, K field, long amount) {
return await(c.hincrby(key, field, amount));
}
+ public Double hincrbyfloat(K key, K field, double amount) {
+ return await(c.hincrbyfloat(key, field, amount));
+ }
+
public Map<K, V> hgetall(K key) {
return await(c.hgetall(key));
}
@@ -231,6 +235,10 @@ public Long incrby(K key, long amount) {
return await(c.incrby(key, amount));
}
+ public Double incrbyfloat(K key, double amount) {
+ return await(c.incrbyfloat(key, amount));
+ }
+
public String info() {
return await(c.info());
}
@@ -319,10 +327,27 @@ public Boolean persist(K key) {
return await(c.persist(key));
}
+ public Boolean pexpire(K key, long milliseconds) {
+ return await(c.pexpire(key, milliseconds));
+ }
+
+ public Boolean pexpireat(K key, Date timestamp) {
+ return await(c.pexpireat(key, timestamp));
+ }
+
+ public Boolean pexpireat(K key, long timestamp) {
+ return await(c.pexpireat(key, timestamp));
+ }
+
+
public String ping() {
return await(c.ping());
}
+ public Long pttl(K key) {
+ return await(c.pttl(key));
+ }
+
public Long publish(K channel, V message) {
return await(c.publish(channel, message));
}
@@ -403,10 +428,15 @@ public Long setrange(K key, long offset, V value) {
return await(c.setrange(key, offset, value));
}
+ @Deprecated
public void shutdown() {
c.shutdown();
}
+ public void shutdown(boolean save) {
+ c.shutdown(save);
+ }
+
public Set<V> sinter(K... keys) {
return await(c.sinter(keys));
}
View
4 src/main/java/com/lambdaworks/redis/protocol/CommandKeyword.java
@@ -9,8 +9,8 @@
*/
public enum CommandKeyword {
AFTER, AGGREGATE, ALPHA, ASC, BEFORE, BY, COUNT, DESC, ENCODING, IDLETIME, KILL,
- LEN, LIMIT, LIST, MAX, MIN, NO, ONE, REFCOUNT, RESET, RESETSTAT, STORE, SUM,
- WEIGHTS, WITHSCORES;
+ LEN, LIMIT, LIST, MAX, MIN, NO, NOSAVE, ONE, REFCOUNT, RESET, RESETSTAT, STORE,
+ SUM, WEIGHTS, WITHSCORES;
public byte[] bytes;
View
8 src/main/java/com/lambdaworks/redis/protocol/CommandType.java
@@ -21,16 +21,16 @@
// Keys
DEL, EXISTS, EXPIRE, EXPIREAT, KEYS, MOVE, OBJECT, PERSIST,
- RANDOMKEY, RENAME, RENAMENX, TTL, TYPE,
+ PEXPIRE, PEXPIREAT, PTTL, RANDOMKEY, RENAME, RENAMENX, TTL, TYPE,
// String
APPEND, GET, GETBIT, GETRANGE, GETSET, MGET, MSET, MSETNX,
SET, SETEX, SETNX, SETBIT, SETRANGE, STRLEN,
- // Integer
+ // Numeric
- DECR, DECRBY, INCR, INCRBY,
+ DECR, DECRBY, INCR, INCRBY, INCRBYFLOAT,
// List
@@ -40,7 +40,7 @@
// Hash
- HDEL, HEXISTS, HGET, HGETALL, HINCRBY, HKEYS, HLEN,
+ HDEL, HEXISTS, HGET, HGETALL, HINCRBY, HINCRBYFLOAT, HKEYS, HLEN,
HMGET, HMSET, HSET, HSETNX, HVALS,
// Transaction
View
25 src/main/javadoc/overview.html
@@ -1,10 +1,11 @@
<body>
<a href="http://github.com/wg/lettuce">lettuce</a> is a scalable thread-safe Java
- {@link com.lambdaworks.redis.RedisClient RedisClient}.
+ {@link com.lambdaworks.redis.RedisClient RedisClient} providing both
+ {@link com.lambdaworks.redis.RedisConnection synchronous} and
+ {@link com.lambdaworks.redis.RedisAsyncConnection asynchronous} connections.
- Multiple threads may share one {@link com.lambdaworks.redis.RedisConnection RedisConnection}
- provided they avoid blocking and transactional operations such as
- <a href="http://redis.io/commands/blpop">BLPOP</a> and
+ Multiple threads may share one connection provided they avoid blocking and transactional
+ operations such as <a href="http://redis.io/commands/blpop">BLPOP</a> and
<a href="http://redis.io/commands/multi">MULTI</a>/<a href="http://redis.io/commands/exec">EXEC</a>.
Multiple open connections are efficiently managed by the excellent
<a href="http://www.jboss.org/netty">netty</a> NIO framework.
@@ -18,18 +19,16 @@
</p>
<p>
- {@link com.lambdaworks.redis.RedisConnection RedisConnections} are designed to be long-lived,
- and if the connection is lost will reconnect until
- {@link com.lambdaworks.redis.RedisConnection#close close} is called. Pending commands that have
- not timed out will be (re)sent after successful reconnection.
+ Redis connections are designed to be long-lived, and if the connection is lost will reconnect
+ until {@code close()} is called. Pending commands that have not timed out will be (re)sent after
+ successful reconnection.
</p>
<p>
- All {@link com.lambdaworks.redis.RedisConnection RedisConnections} inherit a default
- timeout from their {@link com.lambdaworks.redis.RedisClient} and will throw a
- {@link com.lambdaworks.redis.RedisException} when non-blocking commands fail to return
- a result before the timeout expires. The timeout defaults to 60 seconds and
+ All connections inherit a default timeout from their {@link com.lambdaworks.redis.RedisClient}
+ and will throw a {@link com.lambdaworks.redis.RedisException} when non-blocking commands fail
+ to return a result before the timeout expires. The timeout defaults to 60 seconds and
may be changed via {@link com.lambdaworks.redis.RedisClient#setDefaultTimeout} or for
- individual connections with {@link com.lambdaworks.redis.RedisConnection#setTimeout}.
+ each individual connection.
</p>
</body>
View
6 src/test/java/com/lambdaworks/redis/HashCommandTest.java
@@ -56,6 +56,12 @@ public void hincrby() throws Exception {
}
@Test
+ public void hincrbyfloat() throws Exception {
+ assertEquals(1.0, redis.hincrbyfloat(key, "one", 1.0), 0.1);
+ assertEquals(-1.0, redis.hincrbyfloat(key, "one", -2.0), 0.1);
+ }
+
+ @Test
public void hkeys() throws Exception {
assertEquals(list(), redis.hkeys(key));
redis.hset(key, "one", "1");
View
26 src/test/java/com/lambdaworks/redis/KeyCommandTest.java
@@ -103,6 +103,32 @@ public void persist() throws Exception {
}
@Test
+ public void pexpire() throws Exception {
+ assertFalse(redis.pexpire(key, 10));
+ redis.set(key, value);
+ assertTrue(redis.pexpire(key, 10));
+ assertTrue(redis.pttl(key) <= 10 && redis.pttl(key) > 0);
+ }
+
+ @Test
+ public void pexpireat() throws Exception {
+ Date expiration = new Date(System.currentTimeMillis() + 100);
+ assertFalse(redis.pexpireat(key, expiration));
+ redis.set(key, value);
+ assertTrue(redis.pexpireat(key, expiration));
+ assertTrue(redis.pttl(key) <= 100 && redis.pttl(key) > 0);
+ }
+
+ @Test
+ public void pttl() throws Exception {
+ assertEquals(-1, (long) redis.pttl(key));
+ redis.set(key, value);
+ assertEquals(-1, (long) redis.pttl(key));
+ redis.pexpire(key, 10);
+ assertTrue(redis.pttl(key) <= 10 && redis.pttl(key) > 0);
+ }
+
+ @Test
public void randomkey() throws Exception {
assertNull(redis.randomkey());
redis.set(key, value);
View
8 ...lambdaworks/redis/IntegerCommandTest.java → ...lambdaworks/redis/NumericCommandTest.java
@@ -6,7 +6,7 @@
import static org.junit.Assert.*;
-public class IntegerCommandTest extends AbstractCommandTest {
+public class NumericCommandTest extends AbstractCommandTest {
@Test
public void decr() throws Exception {
assertEquals(-1, (long) redis.decr(key));
@@ -30,4 +30,10 @@ public void incrby() throws Exception {
assertEquals(3, (long) redis.incrby(key, 3));
assertEquals(6, (long) redis.incrby(key, 3));
}
+
+ @Test
+ public void incrbyfloat() throws Exception {
+ assertEquals(3.0, redis.incrbyfloat(key, 3.0), 0.1);
+ assertEquals(3.2, redis.incrbyfloat(key, 0.2), 0.1);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.