RList.getAsync method added

pull/100/head
Nikita 10 years ago
parent b8ee305519
commit 0adbcd6afa

@ -27,6 +27,7 @@ import java.util.ListIterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.redisson.async.AsyncOperation; import org.redisson.async.AsyncOperation;
import org.redisson.async.OperationListener;
import org.redisson.async.ResultOperation; import org.redisson.async.ResultOperation;
import org.redisson.async.SyncOperation; import org.redisson.async.SyncOperation;
import org.redisson.connection.ConnectionManager; import org.redisson.connection.ConnectionManager;
@ -161,12 +162,16 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
public Future<Boolean> addAllAsync(final Collection<? extends V> c) { public Future<Boolean> addAllAsync(final Collection<? extends V> c) {
return connectionManager.writeAsync(getName(), new AsyncOperation<Object, Boolean>() { return connectionManager.writeAsync(getName(), new AsyncOperation<Object, Boolean>() {
@Override @Override
public void execute(Promise<Boolean> promise, RedisAsyncConnection<Object, Object> async) { public void execute(final Promise<Boolean> promise, RedisAsyncConnection<Object, Object> async) {
async.rpush((Object)getName(), c.toArray()); async.rpush((Object)getName(), c.toArray()).addListener(new OperationListener<Object, Boolean, Object>(promise, async, this) {
@Override
public void onOperationComplete(Future<Object> future) throws Exception {
promise.setSuccess(true); promise.setSuccess(true);
} }
}); });
} }
});
}
@Override @Override
public boolean addAll(final int index, final Collection<? extends V> coll) { public boolean addAll(final int index, final Collection<? extends V> coll) {
@ -257,13 +262,8 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
} }
@Override @Override
public V get(final int index) { public Future<V> getAsync(final int index) {
checkIndex(index); return connectionManager.readAsync(getName(), new ResultOperation<V, V>() {
return getValue(index);
}
private V getValue(final int index) {
return connectionManager.read(getName(), new ResultOperation<V, V>() {
@Override @Override
protected Future<V> execute(RedisAsyncConnection<Object, V> async) { protected Future<V> execute(RedisAsyncConnection<Object, V> async) {
return async.lindex(getName(), index); return async.lindex(getName(), index);
@ -271,6 +271,16 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
}); });
} }
@Override
public V get(int index) {
checkIndex(index);
return getValue(index);
}
private V getValue(int index) {
return connectionManager.get(getAsync(index));
}
private void checkIndex(int index) { private void checkIndex(int index) {
int size = size(); int size = size();
if (!isInRange(index, size)) if (!isInRange(index, size))

@ -29,6 +29,8 @@ import java.util.List;
*/ */
public interface RList<V> extends List<V>, RExpirable { public interface RList<V> extends List<V>, RExpirable {
Future<V> getAsync(int index);
Future<Boolean> addAsync(V e); Future<Boolean> addAsync(V e);
Future<Boolean> addAllAsync(Collection<? extends V> c); Future<Boolean> addAllAsync(Collection<? extends V> c);

Loading…
Cancel
Save