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 @Override
public void delete() { public boolean delete() {
connectionManager.write(getName(), new SyncOperation<Object, Void>() { return connectionManager.write(getName(), new SyncOperation<Object, Boolean>() {
@Override @Override
public Void execute(RedisConnection<Object, Object> conn) { public Boolean execute(RedisConnection<Object, Object> conn) {
conn.multi(); conn.multi();
conn.del(getName()); conn.del(getName());
conn.publish(getChannelName(), zeroCountMessage); conn.publish(getChannelName(), zeroCountMessage);
if (conn.exec().size() != 2) { if (conn.exec().size() != 2) {
throw new IllegalStateException(); throw new IllegalStateException();
} }
return null; return true;
} }
}); });
} }

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

@ -18,7 +18,8 @@ package org.redisson;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.Promise; 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.connection.ConnectionManager;
import org.redisson.core.RObject; import org.redisson.core.RObject;
@ -48,15 +49,20 @@ abstract class RedissonObject implements RObject {
return name; return name;
} }
public void delete() { public boolean delete() {
delete(getName()); return connectionManager.get(deleteAsync());
} }
void delete(String name) { public Future<Boolean> deleteAsync() {
connectionManager.write(getName(), new ResultOperation<Long, Object>() { return connectionManager.writeAsync(getName(), new AsyncOperation<Object, Boolean>() {
@Override @Override
protected Future<Long> execute(RedisAsyncConnection<Object, Object> async) { public void execute(final Promise<Boolean> promise, RedisAsyncConnection<Object, Object> async) {
return async.del(getName()); 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 @Override
public void delete() { public boolean delete() {
// nothing to delete throw new UnsupportedOperationException();
} }
} }

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

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

Loading…
Cancel
Save