diff --git a/redisson/src/main/java/org/redisson/RedissonKeys.java b/redisson/src/main/java/org/redisson/RedissonKeys.java index 4ffbcf8f8..863a787d2 100644 --- a/redisson/src/main/java/org/redisson/RedissonKeys.java +++ b/redisson/src/main/java/org/redisson/RedissonKeys.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; @@ -384,4 +385,85 @@ public class RedissonKeys implements RKeys { } } + @Override + public long remainTimeToLive(String name) { + return commandExecutor.get(remainTimeToLiveAsync(name)); + } + + @Override + public RFuture remainTimeToLiveAsync(String name) { + return commandExecutor.readAsync(name, StringCodec.INSTANCE, RedisCommands.PTTL, name); + } + + @Override + public void rename(String currentName, String newName) { + commandExecutor.get(renameAsync(currentName, newName)); + } + + @Override + public RFuture renameAsync(String currentName, String newName) { + return commandExecutor.writeAsync(currentName, RedisCommands.RENAME, currentName, newName); + } + + @Override + public boolean renamenx(String oldName, String newName) { + return commandExecutor.get(renamenxAsync(oldName, newName)); + } + + @Override + public RFuture renamenxAsync(String oldName, String newName) { + return commandExecutor.writeAsync(oldName, RedisCommands.RENAMENX, oldName, newName); + } + + @Override + public boolean clearExpire(String name) { + return commandExecutor.get(clearExpireAsync(name)); + } + + @Override + public RFuture clearExpireAsync(String name) { + return commandExecutor.writeAsync(name, StringCodec.INSTANCE, RedisCommands.PERSIST, name); + } + + @Override + public boolean expireAt(String name, long timestamp) { + return commandExecutor.get(expireAtAsync(name, timestamp)); + } + + @Override + public RFuture expireAtAsync(String name, long timestamp) { + return commandExecutor.writeAsync(name, StringCodec.INSTANCE, RedisCommands.PEXPIREAT, name, timestamp); + } + + @Override + public boolean expire(String name, long timeToLive, TimeUnit timeUnit) { + return commandExecutor.get(expireAsync(name, timeToLive, timeUnit)); + } + + @Override + public RFuture expireAsync(String name, long timeToLive, TimeUnit timeUnit) { + return commandExecutor.writeAsync(name, StringCodec.INSTANCE, RedisCommands.PEXPIRE, name, timeUnit.toMillis(timeToLive)); + } + + @Override + public void migrate(String name, String host, int port, int database) { + commandExecutor.get(migrateAsync(name, host, port, database)); + } + + @Override + public RFuture migrateAsync(String name, String host, int port, int database) { + return commandExecutor.writeAsync(name, RedisCommands.MIGRATE, host, port, name, database); + } + + @Override + public boolean move(String name, int database) { + return commandExecutor.get(moveAsync(name, database)); + } + + @Override + public RFuture moveAsync(String name, int database) { + return commandExecutor.writeAsync(name, RedisCommands.MOVE, name, database); + } + + } diff --git a/redisson/src/main/java/org/redisson/api/RKeys.java b/redisson/src/main/java/org/redisson/api/RKeys.java index 31d10a69f..2357fb2f2 100644 --- a/redisson/src/main/java/org/redisson/api/RKeys.java +++ b/redisson/src/main/java/org/redisson/api/RKeys.java @@ -16,6 +16,7 @@ package org.redisson.api; import java.util.Collection; +import java.util.concurrent.TimeUnit; /** * @@ -24,6 +25,83 @@ import java.util.Collection; */ public interface RKeys extends RKeysAsync { + /** + * Move object to another database + * + * @param name of object + * @param database - Redis database number + * @return true if key was moved else false + */ + boolean move(String name, int database); + + /** + * Transfer an object from source Redis instance to destination Redis instance + * + * @param name of object + * @param host - destination host + * @param port - destination port + * @param database - destination database + */ + void migrate(String name, String host, int port, int database); + + /** + * Set a timeout for object. After the timeout has expired, + * the key will automatically be deleted. + * + * @param name of object + * @param timeToLive - timeout before object will be deleted + * @param timeUnit - timeout time unit + * @return true if the timeout was set and false if not + */ + boolean expire(String name, long timeToLive, TimeUnit timeUnit); + + /** + * Set an expire date for object. When expire date comes + * the key will automatically be deleted. + * + * @param name of object + * @param timestamp - expire date in milliseconds (Unix timestamp) + * @return true if the timeout was set and false if not + */ + boolean expireAt(String name, long timestamp); + + /** + * Clear an expire timeout or expire date for object. + * + * @param name of object + * @return true if timeout was removed + * false if object does not exist or does not have an associated timeout + */ + boolean clearExpire(String name); + + /** + * Rename object with oldName to newName + * only if new key is not exists + * + * @param oldName - old name of object + * @param newName - new name of object + * @return true if object has been renamed successfully and false otherwise + */ + boolean renamenx(String oldName, String newName); + + /** + * Rename current object key to newName + * + * @param currentName - current name of object + * @param newName - new name of object + */ + void rename(String currentName, String newName); + + /** + * Remaining time to live of Redisson object that has a timeout + * + * @param name of key + * @return time in milliseconds + * -2 if the key does not exist. + * -1 if the key exists but has no associated expire. + */ + long remainTimeToLive(String name); + /** * Update the last access time of an object. * diff --git a/redisson/src/main/java/org/redisson/api/RKeysAsync.java b/redisson/src/main/java/org/redisson/api/RKeysAsync.java index ccf649ecf..acfebd599 100644 --- a/redisson/src/main/java/org/redisson/api/RKeysAsync.java +++ b/redisson/src/main/java/org/redisson/api/RKeysAsync.java @@ -16,6 +16,7 @@ package org.redisson.api; import java.util.Collection; +import java.util.concurrent.TimeUnit; /** * @@ -24,6 +25,83 @@ import java.util.Collection; */ public interface RKeysAsync { + /** + * Move object to another database + * + * @param name of object + * @param database - Redis database number + * @return true if key was moved else false + */ + RFuture moveAsync(String name, int database); + + /** + * Transfer an object from source Redis instance to destination Redis instance + * + * @param name of object + * @param host - destination host + * @param port - destination port + * @param database - destination database + */ + RFuture migrateAsync(String name, String host, int port, int database); + + /** + * Set a timeout for object. After the timeout has expired, + * the key will automatically be deleted. + * + * @param name of object + * @param timeToLive - timeout before object will be deleted + * @param timeUnit - timeout time unit + * @return true if the timeout was set and false if not + */ + RFuture expireAsync(String name, long timeToLive, TimeUnit timeUnit); + + /** + * Set an expire date for object. When expire date comes + * the key will automatically be deleted. + * + * @param name of object + * @param timestamp - expire date in milliseconds (Unix timestamp) + * @return true if the timeout was set and false if not + */ + RFuture expireAtAsync(String name, long timestamp); + + /** + * Clear an expire timeout or expire date for object. + * + * @param name of object + * @return true if timeout was removed + * false if object does not exist or does not have an associated timeout + */ + RFuture clearExpireAsync(String name); + + /** + * Rename object with oldName to newName + * only if new key is not exists + * + * @param oldName - old name of object + * @param newName - new name of object + * @return true if object has been renamed successfully and false otherwise + */ + RFuture renamenxAsync(String oldName, String newName); + + /** + * Rename current object key to newName + * + * @param currentName - current name of object + * @param newName - new name of object + */ + RFuture renameAsync(String currentName, String newName); + + /** + * Remaining time to live of Redisson object that has a timeout + * + * @param name of key + * @return time in milliseconds + * -2 if the key does not exist. + * -1 if the key exists but has no associated expire. + */ + RFuture remainTimeToLiveAsync(String name); + /** * Update the last access time of an object. *