RExpirableAsync interface added. #186

pull/243/head
Nikita 10 years ago
parent 9a32a175b8
commit 2024094c88

@ -23,6 +23,8 @@ import org.redisson.client.protocol.StringCodec;
import org.redisson.connection.ConnectionManager;
import org.redisson.core.RExpirable;
import io.netty.util.concurrent.Future;
abstract class RedissonExpirable extends RedissonObject implements RExpirable {
RedissonExpirable(ConnectionManager connectionManager, String name) {
@ -30,28 +32,53 @@ abstract class RedissonExpirable extends RedissonObject implements RExpirable {
}
@Override
public boolean expire(final long timeToLive, final TimeUnit timeUnit) {
return connectionManager.write(getName(), StringCodec.INSTANCE, RedisCommands.EXPIRE, getName(), timeUnit.toSeconds(timeToLive));
public boolean expire(long timeToLive, TimeUnit timeUnit) {
return connectionManager.get(expireAsync(timeToLive, timeUnit));
}
@Override
public Future<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit) {
return connectionManager.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.EXPIRE, getName(), timeUnit.toSeconds(timeToLive));
}
@Override
public boolean expireAt(final long timestamp) {
return connectionManager.write(getName(), StringCodec.INSTANCE, RedisCommands.EXPIREAT, getName(), timestamp);
public boolean expireAt(long timestamp) {
return connectionManager.get(expireAtAsync(timestamp));
}
@Override
public boolean expireAt(final Date timestamp) {
public Future<Boolean> expireAtAsync(long timestamp) {
return connectionManager.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.EXPIREAT, getName(), timestamp);
}
@Override
public boolean expireAt(Date timestamp) {
return expireAt(timestamp.getTime() / 1000);
}
@Override
public Future<Boolean> expireAtAsync(Date timestamp) {
return expireAtAsync(timestamp.getTime() / 1000);
}
@Override
public boolean clearExpire() {
return connectionManager.write(getName(), StringCodec.INSTANCE, RedisCommands.PERSIST, getName());
return connectionManager.get(clearExpireAsync());
}
@Override
public Future<Boolean> clearExpireAsync() {
return connectionManager.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.PERSIST, getName());
}
@Override
public long remainTimeToLive() {
return connectionManager.write(getName(), StringCodec.INSTANCE, RedisCommands.TTL, getName());
return connectionManager.get(remainTimeToLiveAsync());
}
@Override
public Future<Long> remainTimeToLiveAsync() {
return connectionManager.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.TTL, getName());
}
}

@ -42,31 +42,37 @@ abstract class RedissonObject implements RObject {
return connectionManager.getGroup().next().<V>newPromise();
}
@Override
public String getName() {
return name;
}
@Override
public boolean rename(String newName) {
return connectionManager.get(renameAsync(newName));
}
@Override
public Future<Boolean> renameAsync(String newName) {
return connectionManager.writeAsync(getName(), RedisCommands.RENAME, getName(), newName);
}
@Override
public boolean renamenx(String newName) {
return connectionManager.get(renamenxAsync(newName));
}
@Override
public Future<Boolean> renamenxAsync(String newName) {
return connectionManager.writeAsync(getName(), RedisCommands.RENAMENX, getName(), newName);
}
@Override
public boolean delete() {
return connectionManager.get(deleteAsync());
}
@Override
public Future<Boolean> deleteAsync() {
return connectionManager.writeAsync(getName(), RedisCommands.DEL_SINGLE, getName());
}

@ -2,7 +2,7 @@ package org.redisson.core;
import io.netty.util.concurrent.Future;
public interface RAtomicLongAsync extends RExpirable {
public interface RAtomicLongAsync extends RExpirableAsync {
Future<Boolean> compareAndSetAsync(long expect, long update);

@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit;
* @author Nikita Koksharov
*
*/
public interface RExpirable extends RObject {
public interface RExpirable extends RObject, RExpirableAsync {
boolean expire(long timeToLive, TimeUnit timeUnit);

@ -0,0 +1,20 @@
package org.redisson.core;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import io.netty.util.concurrent.Future;
public interface RExpirableAsync extends RObjectAsync {
Future<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit);
Future<Boolean> expireAtAsync(Date timestamp);
Future<Boolean> expireAtAsync(long timestamp);
Future<Boolean> clearExpireAsync();
Future<Long> remainTimeToLiveAsync();
}
Loading…
Cancel
Save