Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.redisson.RedissonList Maven / Gradle / Ivy
Go to download
Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava3/Reactive API. Client side caching. Over 50 Redis based Java objects and services: JCache API, Apache Tomcat, Hibernate, Spring, Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Scheduler, RPC
/**
* Copyright (c) 2013-2020 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson;
import org.redisson.api.*;
import org.redisson.api.listener.*;
import org.redisson.api.mapreduce.RCollectionMapReduce;
import org.redisson.client.RedisException;
import org.redisson.client.codec.Codec;
import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommand;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.convertor.BooleanNumberReplayConvertor;
import org.redisson.client.protocol.convertor.Convertor;
import org.redisson.client.protocol.convertor.IntegerReplayConvertor;
import org.redisson.command.CommandAsyncExecutor;
import org.redisson.iterator.RedissonListIterator;
import org.redisson.mapreduce.RedissonCollectionMapReduce;
import org.redisson.misc.CountableListener;
import org.redisson.misc.RPromise;
import org.redisson.misc.RedissonPromise;
import java.util.*;
import java.util.function.Predicate;
import static org.redisson.client.protocol.RedisCommands.*;
/**
* Distributed and concurrent implementation of {@link java.util.List}
*
* @author Nikita Koksharov
*
* @param the type of elements held in this collection
*/
public class RedissonList extends RedissonExpirable implements RList {
private RedissonClient redisson;
public RedissonList(CommandAsyncExecutor commandExecutor, String name, RedissonClient redisson) {
super(commandExecutor, name);
this.redisson = redisson;
}
public RedissonList(Codec codec, CommandAsyncExecutor commandExecutor, String name, RedissonClient redisson) {
super(codec, commandExecutor, name);
this.redisson = redisson;
}
@Override
public RCollectionMapReduce mapReduce() {
return new RedissonCollectionMapReduce(this, redisson, commandExecutor.getConnectionManager());
}
@Override
public int size() {
return get(sizeAsync());
}
public RFuture sizeAsync() {
return commandExecutor.readAsync(getName(), codec, LLEN_INT, getName());
}
@Override
public boolean isEmpty() {
return size() == 0;
}
@Override
public boolean contains(Object o) {
return get(containsAsync(o));
}
@Override
public Iterator iterator() {
return listIterator();
}
@Override
public Object[] toArray() {
List list = readAll();
return list.toArray();
}
@Override
public List readAll() {
return get(readAllAsync());
}
@Override
public RFuture> readAllAsync() {
return commandExecutor.readAsync(getName(), codec, LRANGE, getName(), 0, -1);
}
@Override
public T[] toArray(T[] a) {
List list = readAll();
return list.toArray(a);
}
@Override
public boolean add(V e) {
return get(addAsync(e));
}
@Override
public RFuture addAsync(V e) {
return addAsync(e, RPUSH_BOOLEAN);
}
protected RFuture addAsync(V e, RedisCommand command) {
return commandExecutor.writeAsync(getName(), codec, command, getName(), encode(e));
}
@Override
public boolean remove(Object o) {
return get(removeAsync(o));
}
@Override
public RFuture removeAsync(Object o) {
return removeAsync(o, 1);
}
@Override
public RFuture removeAsync(Object o, int count) {
return commandExecutor.writeAsync(getName(), codec, LREM_SINGLE, getName(), count, encode(o));
}
@Override
public boolean remove(Object o, int count) {
return get(removeAsync(o, count));
}
@Override
public RFuture containsAllAsync(Collection> c) {
if (c.isEmpty()) {
return RedissonPromise.newSucceededFuture(true);
}
return commandExecutor.evalReadAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN,
"local items = redis.call('lrange', KEYS[1], 0, -1) " +
"for i=1, #items do " +
"for j = 1, #ARGV, 1 do " +
"if items[i] == ARGV[j] then " +
"table.remove(ARGV, j) " +
"end " +
"end " +
"end " +
"return #ARGV == 0 and 1 or 0",
Collections.singletonList(getName()), encode(c).toArray());
}
@Override
public boolean containsAll(Collection> c) {
return get(containsAllAsync(c));
}
@Override
public boolean addAll(Collection extends V> c) {
return get(addAllAsync(c));
}
@Override
public RFuture addAllAsync(Collection extends V> c) {
if (c.isEmpty()) {
return RedissonPromise.newSucceededFuture(false);
}
List args = new ArrayList(c.size() + 1);
args.add(getName());
encode(args, c);
return commandExecutor.writeAsync(getName(), codec, RPUSH_BOOLEAN, args.toArray());
}
@Override
public RFuture addAllAsync(int index, Collection extends V> coll) {
if (index < 0) {
throw new IndexOutOfBoundsException("index: " + index);
}
if (coll.isEmpty()) {
return RedissonPromise.newSucceededFuture(false);
}
if (index == 0) { // prepend elements to list
List elements = new ArrayList();
encode(elements, coll);
Collections.reverse(elements);
elements.add(0, getName());
return commandExecutor.writeAsync(getName(), codec, LPUSH_BOOLEAN, elements.toArray());
}
List args = new ArrayList(coll.size() + 1);
args.add(index);
encode(args, coll);
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN,
"local ind = table.remove(ARGV, 1); " + // index is the first parameter
"local size = redis.call('llen', KEYS[1]); " +
"assert(tonumber(ind) <= size, 'index: ' .. ind .. ' but current size: ' .. size); " +
"local tail = redis.call('lrange', KEYS[1], ind, -1); " +
"redis.call('ltrim', KEYS[1], 0, ind - 1); " +
"for i=1, #ARGV, 5000 do "
+ "redis.call('rpush', KEYS[1], unpack(ARGV, i, math.min(i+4999, #ARGV))); "
+ "end " +
"if #tail > 0 then " +
"for i=1, #tail, 5000 do "
+ "redis.call('rpush', KEYS[1], unpack(tail, i, math.min(i+4999, #tail))); "
+ "end "
+ "end;" +
"return 1;",
Collections.singletonList(getName()), args.toArray());
}
@Override
public boolean addAll(int index, Collection extends V> coll) {
return get(addAllAsync(index, coll));
}
@Override
public RFuture removeAllAsync(Collection> c) {
if (c.isEmpty()) {
return RedissonPromise.newSucceededFuture(false);
}
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN,
"local v = 0 " +
"for i = 1, #ARGV, 1 do "
+ "if redis.call('lrem', KEYS[1], 0, ARGV[i]) == 1 "
+ "then v = 1 end "
+"end "
+ "return v ",
Collections.singletonList(getName()), encode(c).toArray());
}
@Override
public boolean removeAll(Collection> c) {
return get(removeAllAsync(c));
}
@Override
public boolean retainAll(Collection> c) {
return get(retainAllAsync(c));
}
@Override
public RFuture retainAllAsync(Collection> c) {
if (c.isEmpty()) {
return deleteAsync();
}
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN,
"local changed = 0 " +
"local items = redis.call('lrange', KEYS[1], 0, -1) "
+ "local i = 1 "
+ "while i <= #items do "
+ "local element = items[i] "
+ "local isInAgrs = false "
+ "for j = 1, #ARGV, 1 do "
+ "if ARGV[j] == element then "
+ "isInAgrs = true "
+ "break "
+ "end "
+ "end "
+ "if isInAgrs == false then "
+ "redis.call('LREM', KEYS[1], 0, element) "
+ "changed = 1 "
+ "end "
+ "i = i + 1 "
+ "end "
+ "return changed ",
Collections.singletonList(getName()), encode(c).toArray());
}
@Override
public void clear() {
delete();
}
@Override
public RFuture getAsync(int index) {
return commandExecutor.readAsync(getName(), codec, LINDEX, getName(), index);
}
public List get(int...indexes) {
return get(getAsync(indexes));
}
public RFuture> getAsync(int...indexes) {
List params = new ArrayList();
for (Integer index : indexes) {
params.add(index);
}
return commandExecutor.evalReadAsync(getName(), codec, RedisCommands.EVAL_LIST,
"local result = {}; " +
"for i = 1, #ARGV, 1 do "
+ "local value = redis.call('lindex', KEYS[1], ARGV[i]);"
+ "table.insert(result, value);" +
"end; " +
"return result;",
Collections.singletonList(getName()), params.toArray());
}
@Override
public V get(int index) {
return getValue(index);
}
V getValue(int index) {
return get(getAsync(index));
}
@Override
public V set(int index, V element) {
try {
return get(setAsync(index, element));
} catch (RedisException e) {
if (e.getCause() instanceof IndexOutOfBoundsException) {
throw (IndexOutOfBoundsException) e.getCause();
}
throw e;
}
}
@Override
public RFuture setAsync(int index, V element) {
RPromise result = new RedissonPromise();
RFuture future = commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_OBJECT,
"local v = redis.call('lindex', KEYS[1], ARGV[1]); " +
"redis.call('lset', KEYS[1], ARGV[1], ARGV[2]); " +
"return v",
Collections.singletonList(getName()), index, encode(element));
future.onComplete((res, e) -> {
if (e != null) {
if (e.getMessage().contains("ERR index out of range")) {
result.tryFailure(new IndexOutOfBoundsException("index out of range"));
return;
}
result.tryFailure(e);
return;
}
result.trySuccess(res);
});
return result;
}
@Override
public void fastSet(int index, V element) {
get(fastSetAsync(index, element));
}
@Override
public RFuture fastSetAsync(int index, V element) {
return commandExecutor.writeAsync(getName(), codec, RedisCommands.LSET, getName(), index, encode(element));
}
@Override
public void add(int index, V element) {
addAll(index, Collections.singleton(element));
}
@Override
public RFuture addAsync(int index, V element) {
return addAllAsync(index, Collections.singleton(element));
}
@Override
public V remove(int index) {
return get(removeAsync(index));
}
@Override
public RFuture removeAsync(int index) {
if (index == 0) {
return commandExecutor.writeAsync(getName(), codec, LPOP, getName());
}
return commandExecutor.evalWriteAsync(getName(), codec, EVAL_OBJECT,
"local v = redis.call('lindex', KEYS[1], ARGV[1]); " +
"redis.call('lset', KEYS[1], ARGV[1], 'DELETED_BY_REDISSON');" +
"redis.call('lrem', KEYS[1], 1, 'DELETED_BY_REDISSON');" +
"return v",
Collections.singletonList(getName()), index);
}
@Override
public void fastRemove(int index) {
get(fastRemoveAsync(index));
}
@Override
public RFuture fastRemoveAsync(int index) {
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_VOID,
"redis.call('lset', KEYS[1], ARGV[1], 'DELETED_BY_REDISSON');" +
"redis.call('lrem', KEYS[1], 1, 'DELETED_BY_REDISSON');",
Collections.singletonList(getName()), index);
}
@Override
public int indexOf(Object o) {
return get(indexOfAsync(o));
}
@Override
public RFuture containsAsync(Object o) {
return indexOfAsync(o, new BooleanNumberReplayConvertor(-1L));
}
public RFuture indexOfAsync(Object o, Convertor convertor) {
return commandExecutor.evalReadAsync(getName(), codec, new RedisCommand("EVAL", convertor),
"local key = KEYS[1] " +
"local obj = ARGV[1] " +
"local items = redis.call('lrange', key, 0, -1) " +
"for i=1,#items do " +
"if items[i] == obj then " +
"return i - 1 " +
"end " +
"end " +
"return -1",
Collections.singletonList(getName()), encode(o));
}
@Override
public RFuture indexOfAsync(Object o) {
return indexOfAsync(o, new IntegerReplayConvertor());
}
@Override
public int lastIndexOf(Object o) {
return get(lastIndexOfAsync(o));
}
@Override
public RFuture lastIndexOfAsync(Object o) {
return commandExecutor.evalReadAsync(getName(), codec, RedisCommands.EVAL_INTEGER,
"local key = KEYS[1] " +
"local obj = ARGV[1] " +
"local items = redis.call('lrange', key, 0, -1) " +
"for i = #items, 1, -1 do " +
"if items[i] == obj then " +
"return i - 1 " +
"end " +
"end " +
"return -1",
Collections.singletonList(getName()), encode(o));
}
public RFuture lastIndexOfAsync(Object o, Convertor convertor) {
return commandExecutor.evalReadAsync(getName(), codec, new RedisCommand("EVAL", convertor),
"local key = KEYS[1] " +
"local obj = ARGV[1] " +
"local items = redis.call('lrange', key, 0, -1) " +
"for i = #items, 1, -1 do " +
"if items[i] == obj then " +
"return i - 1 " +
"end " +
"end " +
"return -1",
Collections.singletonList(getName()), encode(o));
}
@Override
public void trim(int fromIndex, int toIndex) {
get(trimAsync(fromIndex, toIndex));
}
@Override
public RFuture trimAsync(int fromIndex, int toIndex) {
return commandExecutor.writeAsync(getName(), codec, RedisCommands.LTRIM, getName(), fromIndex, toIndex);
}
@Override
public ListIterator listIterator() {
return listIterator(0);
}
@Override
public ListIterator listIterator(int ind) {
return new RedissonListIterator(ind) {
@Override
public V getValue(int index) {
return RedissonList.this.getValue(index);
}
@Override
public V remove(int index) {
return RedissonList.this.remove(index);
}
@Override
public void fastSet(int index, V value) {
RedissonList.this.fastSet(index, value);
}
@Override
public void add(int index, V value) {
RedissonList.this.add(index, value);
}
};
}
@Override
public RList subList(int fromIndex, int toIndex) {
int size = size();
if (fromIndex < 0 || toIndex > size) {
throw new IndexOutOfBoundsException("fromIndex: " + fromIndex + " toIndex: " + toIndex + " size: " + size);
}
if (fromIndex > toIndex) {
throw new IllegalArgumentException("fromIndex: " + fromIndex + " toIndex: " + toIndex);
}
return new RedissonSubList(codec, commandExecutor, getName(), fromIndex, toIndex);
}
@Override
@SuppressWarnings("AvoidInlineConditionals")
public String toString() {
Iterator it = iterator();
if (! it.hasNext())
return "[]";
StringBuilder sb = new StringBuilder();
sb.append('[');
for (;;) {
V e = it.next();
sb.append(e == this ? "(this Collection)" : e);
if (! it.hasNext())
return sb.append(']').toString();
sb.append(',').append(' ');
}
}
@Override
@SuppressWarnings("AvoidInlineConditionals")
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof List))
return false;
Iterator e1 = iterator();
Iterator> e2 = ((List>) o).iterator();
while (e1.hasNext() && e2.hasNext()) {
V o1 = e1.next();
Object o2 = e2.next();
if (!(o1==null ? o2==null : o1.equals(o2)))
return false;
}
return !(e1.hasNext() || e2.hasNext());
}
@Override
@SuppressWarnings("AvoidInlineConditionals")
public int hashCode() {
int hashCode = 1;
for (V e : this) {
hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
}
return hashCode;
}
@Override
public RFuture addAfterAsync(V elementToFind, V element) {
return commandExecutor.writeAsync(getName(), codec, RedisCommands.LINSERT_INT, getName(), "AFTER", encode(elementToFind), encode(element));
}
@Override
public RFuture addBeforeAsync(V elementToFind, V element) {
return commandExecutor.writeAsync(getName(), codec, RedisCommands.LINSERT_INT, getName(), "BEFORE", encode(elementToFind), encode(element));
}
@Override
public int addAfter(V elementToFind, V element) {
return get(addAfterAsync(elementToFind, element));
}
@Override
public int addBefore(V elementToFind, V element) {
return get(addBeforeAsync(elementToFind, element));
}
@Override
public List readSort(SortOrder order) {
return get(readSortAsync(order));
}
@Override
public RFuture> readSortAsync(SortOrder order) {
return commandExecutor.readAsync(getName(), codec, RedisCommands.SORT_LIST, getName(), order);
}
@Override
public List readSort(SortOrder order, int offset, int count) {
return get(readSortAsync(order, offset, count));
}
@Override
public RFuture> readSortAsync(SortOrder order, int offset, int count) {
return commandExecutor.readAsync(getName(), codec, RedisCommands.SORT_LIST, getName(), "LIMIT", offset, count, order);
}
@Override
public List readSort(String byPattern, SortOrder order) {
return get(readSortAsync(byPattern, order));
}
@Override
public RFuture> readSortAsync(String byPattern, SortOrder order) {
return commandExecutor.readAsync(getName(), codec, RedisCommands.SORT_LIST, getName(), "BY", byPattern, order);
}
@Override
public List readSort(String byPattern, SortOrder order, int offset, int count) {
return get(readSortAsync(byPattern, order, offset, count));
}
@Override
public RFuture> readSortAsync(String byPattern, SortOrder order, int offset, int count) {
return commandExecutor.readAsync(getName(), codec, RedisCommands.SORT_LIST, getName(), "BY", byPattern, "LIMIT", offset, count, order);
}
@Override
public Collection readSort(String byPattern, List getPatterns, SortOrder order) {
return (Collection) get(readSortAsync(byPattern, getPatterns, order));
}
@Override
public RFuture> readSortAsync(String byPattern, List getPatterns, SortOrder order) {
return readSortAsync(byPattern, getPatterns, order, -1, -1);
}
@Override
public Collection readSort(String byPattern, List getPatterns, SortOrder order, int offset, int count) {
return (Collection) get(readSortAsync(byPattern, getPatterns, order, offset, count));
}
@Override
public RFuture> readSortAsync(String byPattern, List getPatterns, SortOrder order, int offset, int count) {
return readSortAsync(byPattern, getPatterns, order, offset, count, false);
}
@Override
public List readSortAlpha(SortOrder order) {
return get(readSortAlphaAsync(order));
}
@Override
public RFuture> readSortAlphaAsync(SortOrder order) {
return commandExecutor.readAsync(getName(), codec, RedisCommands.SORT_LIST, getName(), "ALPHA", order);
}
@Override
public List readSortAlpha(SortOrder order, int offset, int count) {
return get(readSortAlphaAsync(order, offset, count));
}
@Override
public RFuture> readSortAlphaAsync(SortOrder order, int offset, int count) {
return commandExecutor.readAsync(getName(), codec, RedisCommands.SORT_LIST, getName(), "LIMIT", offset, count, "ALPHA", order);
}
@Override
public List readSortAlpha(String byPattern, SortOrder order) {
return get(readSortAlphaAsync(byPattern, order));
}
@Override
public RFuture> readSortAlphaAsync(String byPattern, SortOrder order) {
return commandExecutor.readAsync(getName(), codec, RedisCommands.SORT_LIST, getName(), "BY", byPattern, "ALPHA", order);
}
@Override
public List readSortAlpha(String byPattern, SortOrder order, int offset, int count) {
return get(readSortAlphaAsync(byPattern, order, offset, count));
}
@Override
public RFuture> readSortAlphaAsync(String byPattern, SortOrder order, int offset, int count) {
return commandExecutor.readAsync(getName(), codec, RedisCommands.SORT_LIST, getName(), "BY", byPattern, "LIMIT", offset, count, "ALPHA", order);
}
@Override
public Collection readSortAlpha(String byPattern, List getPatterns, SortOrder order) {
return (Collection) get(readSortAlphaAsync(byPattern, getPatterns, order));
}
@Override
public RFuture> readSortAlphaAsync(String byPattern, List getPatterns, SortOrder order) {
return readSortAlphaAsync(byPattern, getPatterns, order, -1, -1);
}
@Override
public Collection readSortAlpha(String byPattern, List getPatterns, SortOrder order, int offset, int count) {
return (Collection) get(readSortAlphaAsync(byPattern, getPatterns, order, offset, count));
}
@Override
public RFuture> readSortAlphaAsync(String byPattern, List getPatterns, SortOrder order, int offset, int count) {
return readSortAsync(byPattern, getPatterns, order, offset, count, true);
}
@Override
public int sortTo(String destName, SortOrder order) {
return get(sortToAsync(destName, order));
}
@Override
public RFuture sortToAsync(String destName, SortOrder order) {
return sortToAsync(destName, null, Collections.emptyList(), order, -1, -1);
}
@Override
public int sortTo(String destName, SortOrder order, int offset, int count) {
return get(sortToAsync(destName, order, offset, count));
}
@Override
public RFuture sortToAsync(String destName, SortOrder order, int offset, int count) {
return sortToAsync(destName, null, Collections.emptyList(), order, offset, count);
}
@Override
public int sortTo(String destName, String byPattern, SortOrder order, int offset, int count) {
return get(sortToAsync(destName, byPattern, order, offset, count));
}
@Override
public int sortTo(String destName, String byPattern, SortOrder order) {
return get(sortToAsync(destName, byPattern, order));
}
@Override
public RFuture sortToAsync(String destName, String byPattern, SortOrder order) {
return sortToAsync(destName, byPattern, Collections.emptyList(), order, -1, -1);
}
@Override
public RFuture sortToAsync(String destName, String byPattern, SortOrder order, int offset, int count) {
return sortToAsync(destName, byPattern, Collections.emptyList(), order, offset, count);
}
@Override
public int sortTo(String destName, String byPattern, List getPatterns, SortOrder order) {
return get(sortToAsync(destName, byPattern, getPatterns, order));
}
@Override
public RFuture sortToAsync(String destName, String byPattern, List getPatterns, SortOrder order) {
return sortToAsync(destName, byPattern, getPatterns, order, -1, -1);
}
@Override
public int sortTo(String destName, String byPattern, List getPatterns, SortOrder order, int offset, int count) {
return get(sortToAsync(destName, byPattern, getPatterns, order, offset, count));
}
@Override
public RFuture sortToAsync(String destName, String byPattern, List getPatterns, SortOrder order, int offset, int count) {
List params = new ArrayList();
params.add(getName());
if (byPattern != null) {
params.add("BY");
params.add(byPattern);
}
if (offset != -1 && count != -1) {
params.add("LIMIT");
}
if (offset != -1) {
params.add(offset);
}
if (count != -1) {
params.add(count);
}
for (String pattern : getPatterns) {
params.add("GET");
params.add(pattern);
}
params.add(order);
params.add("STORE");
params.add(destName);
return commandExecutor.writeAsync(getName(), codec, RedisCommands.SORT_TO, params.toArray());
}
private RFuture> readSortAsync(String byPattern, List getPatterns, SortOrder order, int offset, int count, boolean alpha) {
List params = new ArrayList();
params.add(getName());
if (byPattern != null) {
params.add("BY");
params.add(byPattern);
}
if (offset != -1 && count != -1) {
params.add("LIMIT");
}
if (offset != -1) {
params.add(offset);
}
if (count != -1) {
params.add(count);
}
if (getPatterns != null) {
for (String pattern : getPatterns) {
params.add("GET");
params.add(pattern);
}
}
if (alpha) {
params.add("ALPHA");
}
if (order != null) {
params.add(order);
}
return commandExecutor.readAsync(getName(), codec, RedisCommands.SORT_LIST, params.toArray());
}
@Override
public RFuture> rangeAsync(int toIndex) {
return rangeAsync(0, toIndex);
}
@Override
public RFuture> rangeAsync(int fromIndex, int toIndex) {
return commandExecutor.readAsync(getName(), codec, LRANGE, getName(), fromIndex, toIndex);
}
@Override
public List range(int toIndex) {
return get(rangeAsync(toIndex));
}
@Override
public List range(int fromIndex, int toIndex) {
return get(rangeAsync(fromIndex, toIndex));
}
@Override
public int addListener(ObjectListener listener) {
if (listener instanceof ListAddListener) {
return addListener("__keyevent@*:rpush", (ListAddListener) listener, ListAddListener::onListAdd);
}
if (listener instanceof ListRemoveListener) {
return addListener("__keyevent@*:lrem", (ListRemoveListener) listener, ListRemoveListener::onListRemove);
}
if (listener instanceof ListTrimListener) {
return addListener("__keyevent@*:ltrim", (ListTrimListener) listener, ListTrimListener::onListTrim);
}
if (listener instanceof ListSetListener) {
return addListener("__keyevent@*:lset", (ListSetListener) listener, ListSetListener::onListSet);
}
if (listener instanceof ListInsertListener) {
return addListener("__keyevent@*:linsert", (ListInsertListener) listener, ListInsertListener::onListInsert);
}
return super.addListener(listener);
};
@Override
public RFuture addListenerAsync(ObjectListener listener) {
if (listener instanceof ListAddListener) {
return addListenerAsync("__keyevent@*:rpush", (ListAddListener) listener, ListAddListener::onListAdd);
}
if (listener instanceof ListRemoveListener) {
return addListenerAsync("__keyevent@*:lrem", (ListRemoveListener) listener, ListRemoveListener::onListRemove);
}
if (listener instanceof ListTrimListener) {
return addListenerAsync("__keyevent@*:ltrim", (ListTrimListener) listener, ListTrimListener::onListTrim);
}
if (listener instanceof ListSetListener) {
return addListenerAsync("__keyevent@*:lset", (ListSetListener) listener, ListSetListener::onListSet);
}
if (listener instanceof ListInsertListener) {
return addListenerAsync("__keyevent@*:linsert", (ListInsertListener) listener, ListInsertListener::onListInsert);
}
return super.addListenerAsync(listener);
}
@Override
public void removeListener(int listenerId) {
RPatternTopic addTopic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:rpush");
addTopic.removeListener(listenerId);
RPatternTopic remTopic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:lrem");
remTopic.removeListener(listenerId);
RPatternTopic trimTopic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:ltrim");
trimTopic.removeListener(listenerId);
RPatternTopic setTopic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:lset");
setTopic.removeListener(listenerId);
RPatternTopic insertTopic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:linsert");
insertTopic.removeListener(listenerId);
super.removeListener(listenerId);
}
@Override
public RFuture removeListenerAsync(int listenerId) {
RPromise result = new RedissonPromise<>();
CountableListener listener = new CountableListener<>(result, null, 5);
RPatternTopic addTopic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:rpush");
addTopic.removeListenerAsync(listenerId).onComplete(listener);
RPatternTopic remTopic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:lrem");
remTopic.removeListenerAsync(listenerId).onComplete(listener);
RPatternTopic trimTopic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:ltrim");
trimTopic.removeListenerAsync(listenerId).onComplete(listener);
RPatternTopic setTopic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:lset");
setTopic.removeListenerAsync(listenerId).onComplete(listener);
RPatternTopic insertTopic = new RedissonPatternTopic(StringCodec.INSTANCE, commandExecutor, "__keyevent@*:linsert");
insertTopic.removeListenerAsync(listenerId).onComplete(listener);
removeListenersAsync(listenerId, listener);
return result;
}
@Override
public boolean removeIf(Predicate super V> filter) {
throw new UnsupportedOperationException();
}
}