Add Redis 2.6 millisecond expiration commands
DATAREDIS-178 Add pExpire, pExpireAt, pTTl ops to connections
This commit is contained in:
@@ -1166,4 +1166,28 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
public Object execute(String command, String... args) {
|
||||
return execute(command, serializeMulti(args));
|
||||
}
|
||||
|
||||
public Boolean pExpire(byte[] key, long millis) {
|
||||
return delegate.pExpire(key, millis);
|
||||
}
|
||||
|
||||
public Boolean pExpireAt(byte[] key, long unixTimeInMillis) {
|
||||
return delegate.pExpireAt(key, unixTimeInMillis);
|
||||
}
|
||||
|
||||
public Long pTtl(byte[] key) {
|
||||
return delegate.pTtl(key);
|
||||
}
|
||||
|
||||
public Boolean pExpire(String key, long millis) {
|
||||
return pExpire(serialize(key), millis);
|
||||
}
|
||||
|
||||
public Boolean pExpireAt(String key, long unixTimeInMillis) {
|
||||
return pExpireAt(serialize(key), unixTimeInMillis);
|
||||
}
|
||||
|
||||
public Long pTtl(String key) {
|
||||
return pTtl(serialize(key));
|
||||
}
|
||||
}
|
||||
@@ -42,14 +42,20 @@ public interface RedisKeyCommands {
|
||||
|
||||
Boolean expire(byte[] key, long seconds);
|
||||
|
||||
Boolean pExpire(byte[] key, long millis);
|
||||
|
||||
Boolean expireAt(byte[] key, long unixTime);
|
||||
|
||||
Boolean pExpireAt(byte[] key, long unixTimeInMillis);
|
||||
|
||||
Boolean persist(byte[] key);
|
||||
|
||||
Boolean move(byte[] key, int dbIndex);
|
||||
|
||||
Long ttl(byte[] key);
|
||||
|
||||
Long pTtl(byte[] key);
|
||||
|
||||
// sort commands
|
||||
List<byte[]> sort(byte[] key, SortParameters params);
|
||||
|
||||
|
||||
@@ -60,14 +60,20 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
|
||||
Boolean expire(String key, long seconds);
|
||||
|
||||
Boolean pExpire(String key, long millis);
|
||||
|
||||
Boolean expireAt(String key, long unixTime);
|
||||
|
||||
Boolean pExpireAt(String key, long unixTimeInMillis);
|
||||
|
||||
Boolean persist(String key);
|
||||
|
||||
Boolean move(String key, int dbIndex);
|
||||
|
||||
Long ttl(String key);
|
||||
|
||||
Long pTtl(String key);
|
||||
|
||||
String echo(String message);
|
||||
|
||||
// sort commands
|
||||
|
||||
@@ -811,6 +811,17 @@ public class JedisConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean pExpire(byte[] key, long millis) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Boolean pExpireAt(byte[] key, long unixTimeInMillis) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Long pTtl(byte[] key) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public DataType type(byte[] key) {
|
||||
try {
|
||||
|
||||
@@ -343,6 +343,17 @@ public class JredisConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean pExpire(byte[] key, long millis) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Boolean pExpireAt(byte[] key, long unixTimeInMillis) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Long pTtl(byte[] key) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Set<byte[]> keys(byte[] pattern) {
|
||||
try {
|
||||
|
||||
@@ -555,6 +555,41 @@ public class LettuceConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean pExpire(byte[] key, long millis) {
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(getAsyncConnection().pexpire(key, millis));
|
||||
return null;
|
||||
}
|
||||
return getConnection().pexpire(key, millis);
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean pExpireAt(byte[] key, long unixTimeInMillis) {
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(getAsyncConnection().pexpireat(key, unixTimeInMillis));
|
||||
return null;
|
||||
}
|
||||
return getConnection().pexpireat(key, unixTimeInMillis);
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Long pTtl(byte[] key) {
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(getAsyncConnection().pttl(key));
|
||||
return null;
|
||||
}
|
||||
return getConnection().pttl(key);
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<byte[]> keys(byte[] pattern) {
|
||||
try {
|
||||
|
||||
@@ -479,6 +479,29 @@ public class SrpConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean pExpire(byte[] key, long millis) {
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(pipeline.pexpire(key, millis));
|
||||
return null;
|
||||
}
|
||||
return SrpUtils.asBoolean(client.pexpire(key, millis));
|
||||
} catch (Exception ex) {
|
||||
throw convertSrpAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean pExpireAt(byte[] key, long unixTimeInMillis) {
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(pipeline.pexpireat(key, unixTimeInMillis));
|
||||
return null;
|
||||
}
|
||||
return SrpUtils.asBoolean(client.pexpireat(key, unixTimeInMillis));
|
||||
} catch (Exception ex) {
|
||||
throw convertSrpAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<byte[]> keys(byte[] pattern) {
|
||||
try {
|
||||
@@ -596,6 +619,17 @@ public class SrpConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
public Long pTtl(byte[] key) {
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(pipeline.pttl(key));
|
||||
return null;
|
||||
}
|
||||
return client.pttl(key).data();
|
||||
} catch (Exception ex) {
|
||||
throw convertSrpAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public DataType type(byte[] key) {
|
||||
try {
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.util.Assert;
|
||||
|
||||
import redis.client.RedisException;
|
||||
import redis.reply.BulkReply;
|
||||
import redis.reply.IntegerReply;
|
||||
import redis.reply.MultiBulkReply;
|
||||
import redis.reply.Reply;
|
||||
|
||||
@@ -175,6 +176,13 @@ abstract class SrpUtils {
|
||||
return map;
|
||||
}
|
||||
|
||||
static Boolean asBoolean(IntegerReply reply) {
|
||||
if (reply == null) {
|
||||
return null;
|
||||
}
|
||||
return (Long.valueOf(1).equals(reply.data()));
|
||||
}
|
||||
|
||||
static byte[] limit(long offset, long count) {
|
||||
return ("LIMIT " + offset + " " + count).getBytes(Charsets.UTF_8);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user