|
|
|
@ -15,8 +15,6 @@
|
|
|
|
|
*/
|
|
|
|
|
package org.redisson;
|
|
|
|
|
|
|
|
|
|
import java.util.NoSuchElementException;
|
|
|
|
|
|
|
|
|
|
import org.redisson.api.RFuture;
|
|
|
|
|
import org.redisson.api.RQueue;
|
|
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
|
@ -24,6 +22,10 @@ import org.redisson.client.codec.Codec;
|
|
|
|
|
import org.redisson.client.protocol.RedisCommands;
|
|
|
|
|
import org.redisson.command.CommandAsyncExecutor;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.NoSuchElementException;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Distributed and concurrent implementation of {@link java.util.Queue}
|
|
|
|
|
*
|
|
|
|
@ -77,6 +79,27 @@ public class RedissonQueue<V> extends RedissonList<V> implements RQueue<V> {
|
|
|
|
|
return commandExecutor.writeAsync(getName(), codec, RedisCommands.LPOP, getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<V> poll(int limit) {
|
|
|
|
|
return get(pollAsync(limit));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<List<V>> pollAsync(int limit) {
|
|
|
|
|
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_LIST,
|
|
|
|
|
"local result = {};"
|
|
|
|
|
+ "for i = 1, ARGV[1], 1 do " +
|
|
|
|
|
"local value = redis.call('lpop', KEYS[1]);" +
|
|
|
|
|
"if value ~= false then " +
|
|
|
|
|
"table.insert(result, value);" +
|
|
|
|
|
"else " +
|
|
|
|
|
"return result;" +
|
|
|
|
|
"end;" +
|
|
|
|
|
"end; " +
|
|
|
|
|
"return result;",
|
|
|
|
|
Collections.singletonList(getName()), limit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public V poll() {
|
|
|
|
|
return get(pollAsync());
|
|
|
|
|