expire, expireAt, move, migrate, clearExpire, renamenx, rename, remainTimeToLive methods added to RKey

pull/830/head^2
Nikita 8 years ago
parent dccc9dc153
commit a91d54227d

@ -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<Long> 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<Void> 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<Boolean> 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<Boolean> 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<Boolean> 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<Boolean> 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<Void> 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<Boolean> moveAsync(String name, int database) {
return commandExecutor.writeAsync(name, RedisCommands.MOVE, name, database);
}
}

@ -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 <code>true</code> if key was moved else <code>false</code>
*/
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 <code>true</code> if the timeout was set and <code>false</code> 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 <code>true</code> if the timeout was set and <code>false</code> if not
*/
boolean expireAt(String name, long timestamp);
/**
* Clear an expire timeout or expire date for object.
*
* @param name of object
* @return <code>true</code> if timeout was removed
* <code>false</code> if object does not exist or does not have an associated timeout
*/
boolean clearExpire(String name);
/**
* Rename object with <code>oldName</code> to <code>newName</code>
* only if new key is not exists
*
* @param oldName - old name of object
* @param newName - new name of object
* @return <code>true</code> if object has been renamed successfully and <code>false</code> otherwise
*/
boolean renamenx(String oldName, String newName);
/**
* Rename current object key to <code>newName</code>
*
* @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.
*

@ -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 <code>true</code> if key was moved else <code>false</code>
*/
RFuture<Boolean> 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<Void> 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 <code>true</code> if the timeout was set and <code>false</code> if not
*/
RFuture<Boolean> 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 <code>true</code> if the timeout was set and <code>false</code> if not
*/
RFuture<Boolean> expireAtAsync(String name, long timestamp);
/**
* Clear an expire timeout or expire date for object.
*
* @param name of object
* @return <code>true</code> if timeout was removed
* <code>false</code> if object does not exist or does not have an associated timeout
*/
RFuture<Boolean> clearExpireAsync(String name);
/**
* Rename object with <code>oldName</code> to <code>newName</code>
* only if new key is not exists
*
* @param oldName - old name of object
* @param newName - new name of object
* @return <code>true</code> if object has been renamed successfully and <code>false</code> otherwise
*/
RFuture<Boolean> renamenxAsync(String oldName, String newName);
/**
* Rename current object key to <code>newName</code>
*
* @param currentName - current name of object
* @param newName - new name of object
*/
RFuture<Void> 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<Long> remainTimeToLiveAsync(String name);
/**
* Update the last access time of an object.
*

Loading…
Cancel
Save