delete method now returns boolean value. deleteAsync method added

pull/100/head
Nikita 10 years ago
parent 600eb79481
commit fd5c610080

@ -263,17 +263,17 @@ public class RedissonCountDownLatch extends RedissonObject implements RCountDown
}
@Override
public void delete() {
connectionManager.write(getName(), new SyncOperation<Object, Void>() {
public boolean delete() {
return connectionManager.write(getName(), new SyncOperation<Object, Boolean>() {
@Override
public Void execute(RedisConnection<Object, Object> conn) {
public Boolean execute(RedisConnection<Object, Object> conn) {
conn.multi();
conn.del(getName());
conn.publish(getChannelName(), zeroCountMessage);
if (conn.exec().size() != 2) {
throw new IllegalStateException();
}
return null;
return true;
}
});
}

@ -490,8 +490,9 @@ public class RedissonLock extends RedissonObject implements RLock {
}
@Override
public void delete() {
public boolean delete() {
forceUnlock();
return true;
}
}

@ -18,7 +18,8 @@ package org.redisson;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.Promise;
import org.redisson.async.ResultOperation;
import org.redisson.async.AsyncOperation;
import org.redisson.async.OperationListener;
import org.redisson.connection.ConnectionManager;
import org.redisson.core.RObject;
@ -48,17 +49,22 @@ abstract class RedissonObject implements RObject {
return name;
}
public void delete() {
delete(getName());
public boolean delete() {
return connectionManager.get(deleteAsync());
}
void delete(String name) {
connectionManager.write(getName(), new ResultOperation<Long, Object>() {
public Future<Boolean> deleteAsync() {
return connectionManager.writeAsync(getName(), new AsyncOperation<Object, Boolean>() {
@Override
protected Future<Long> execute(RedisAsyncConnection<Object, Object> async) {
return async.del(getName());
public void execute(final Promise<Boolean> promise, RedisAsyncConnection<Object, Object> async) {
async.del(getName()).addListener(new OperationListener<Object, Boolean, Object>(promise, async, this) {
@Override
public void onOperationComplete(Future<Object> future) throws Exception {
promise.setSuccess(((Number) future.get()).byteValue() == 1);
}
});
}
});
}
}

@ -92,8 +92,8 @@ public class RedissonTopic<M> extends RedissonObject implements RTopic<M> {
}
@Override
public void delete() {
// nothing to delete
public boolean delete() {
throw new UnsupportedOperationException();
}
}

@ -15,6 +15,8 @@
*/
package org.redisson.core;
import io.netty.util.concurrent.Future;
/**
* Base interface for all Redisson objects
*
@ -33,6 +35,8 @@ public interface RObject {
/**
* Deletes the object
*/
void delete();
boolean delete();
Future<Boolean> deleteAsync();
}

@ -25,8 +25,9 @@ public class RedissonBucketTest extends BaseTest {
String value = "somevalue";
bucket.set(value);
Assert.assertEquals(value, bucket.get());
bucket.delete();
Assert.assertTrue(bucket.delete());
Assert.assertNull(bucket.get());
Assert.assertFalse(bucket.delete());
}

Loading…
Cancel
Save