Feature - range method added to RList, RListReactive and RListRx interfaces. #2080

pull/2085/head
Nikita Koksharov 6 years ago
parent 89daf178d9
commit 8f20f97e34

@ -915,4 +915,24 @@ public class RedissonList<V> extends RedissonExpirable implements RList<V> {
return commandExecutor.readAsync(getName(), codec, RedisCommands.SORT_LIST, params.toArray());
}
@Override
public RFuture<List<V>> rangeAsync(int toIndex) {
return rangeAsync(0, toIndex);
}
@Override
public RFuture<List<V>> rangeAsync(int fromIndex, int toIndex) {
return commandExecutor.readAsync(getName(), codec, LRANGE, getName(), fromIndex, toIndex);
}
@Override
public List<V> range(int toIndex) {
return get(rangeAsync(toIndex));
}
@Override
public List<V> range(int fromIndex, int toIndex) {
return get(rangeAsync(fromIndex, toIndex));
}
}

@ -164,18 +164,7 @@ public class RedissonListMultimapValues<V> extends RedissonExpirable implements
@Override
public RFuture<List<V>> readAllAsync() {
return commandExecutor.evalReadAsync(getName(), codec, RedisCommands.EVAL_MAP_VALUE_LIST,
"local expireDate = 92233720368547758; " +
"local expireDateScore = redis.call('zscore', KEYS[1], ARGV[2]); "
+ "if expireDateScore ~= false then "
+ "expireDate = tonumber(expireDateScore) "
+ "end; "
+ "if expireDate <= tonumber(ARGV[1]) then "
+ "return {};"
+ "end; "
+ "return redis.call('lrange', KEYS[2], 0, -1);",
Arrays.<Object>asList(timeoutSetName, getName()),
System.currentTimeMillis(), encodeMapKey(key));
return rangeAsync(0, -1);
}
@Override
@ -893,6 +882,37 @@ public class RedissonListMultimapValues<V> extends RedissonExpirable implements
return list.sortToAsync(destName, byPattern, getPatterns, order, offset, count);
}
@Override
public RFuture<List<V>> rangeAsync(int toIndex) {
return rangeAsync(0, toIndex);
}
@Override
public RFuture<List<V>> rangeAsync(int fromIndex, int toIndex) {
return commandExecutor.evalReadAsync(getName(), codec, RedisCommands.EVAL_MAP_VALUE_LIST,
"local expireDate = 92233720368547758; " +
"local expireDateScore = redis.call('zscore', KEYS[1], ARGV[2]); "
+ "if expireDateScore ~= false then "
+ "expireDate = tonumber(expireDateScore) "
+ "end; "
+ "if expireDate <= tonumber(ARGV[1]) then "
+ "return {};"
+ "end; "
+ "return redis.call('lrange', KEYS[2], ARGV[3], ARGV[4]);",
Arrays.<Object>asList(timeoutSetName, getName()),
System.currentTimeMillis(), encodeMapKey(key), fromIndex, toIndex);
}
@Override
public List<V> range(int toIndex) {
return get(rangeAsync(toIndex));
}
@Override
public List<V> range(int fromIndex, int toIndex) {
return get(rangeAsync(fromIndex, toIndex));
}
}

@ -92,6 +92,25 @@ public interface RList<V> extends List<V>, RExpirable, RListAsync<V>, RSortable<
*/
void trim(int fromIndex, int toIndex);
/**
* Returns range of values from 0 index to <code>toIndex</code>. Indexes are zero based.
* <code>-1</code> means the last element, <code>-2</code> means penultimate and so on.
*
* @param toIndex - end index
* @return
*/
List<V> range(int toIndex);
/**
* Returns range of values from <code>fromIndex</code> to <code>toIndex</code> index including.
* Indexes are zero based. <code>-1</code> means the last element, <code>-2</code> means penultimate and so on.
*
* @param fromIndex - start index
* @param toIndex - end index
* @return
*/
List<V> range(int fromIndex, int toIndex);
/**
* Remove object by specified index
*

@ -166,4 +166,23 @@ public interface RListAsync<V> extends RCollectionAsync<V>, RSortableAsync<List<
*/
RFuture<Boolean> removeAsync(Object element, int count);
/**
* Returns range of values from 0 index to <code>toIndex</code>. Indexes are zero based.
* <code>-1</code> means the last element, <code>-2</code> means penultimate and so on.
*
* @param toIndex - end index
* @return
*/
RFuture<List<V>> rangeAsync(int toIndex);
/**
* Returns range of values from <code>fromIndex</code> to <code>toIndex</code> index including.
* Indexes are zero based. <code>-1</code> means the last element, <code>-2</code> means penultimate and so on.
*
* @param fromIndex - start index
* @param toIndex - end index
* @return
*/
RFuture<List<V>> rangeAsync(int fromIndex, int toIndex);
}

@ -162,5 +162,24 @@ public interface RListReactive<V> extends RCollectionReactive<V>, RSortableReact
* @return void
*/
Mono<Void> fastRemove(int index);
/**
* Returns range of values from 0 index to <code>toIndex</code>. Indexes are zero based.
* <code>-1</code> means the last element, <code>-2</code> means penultimate and so on.
*
* @param toIndex - end index
* @return
*/
Mono<List<V>> range(int toIndex);
/**
* Returns range of values from <code>fromIndex</code> to <code>toIndex</code> index including.
* Indexes are zero based. <code>-1</code> means the last element, <code>-2</code> means penultimate and so on.
*
* @param fromIndex - start index
* @param toIndex - end index
* @return
*/
Mono<List<V>> range(int fromIndex, int toIndex);
}

@ -164,5 +164,24 @@ public interface RListRx<V> extends RCollectionRx<V>, RSortableRx<List<V>> {
* @return void
*/
Completable fastRemove(int index);
/**
* Returns range of values from 0 index to <code>toIndex</code>. Indexes are zero based.
* <code>-1</code> means the last element, <code>-2</code> means penultimate and so on.
*
* @param toIndex - end index
* @return
*/
Single<List<V>> range(int toIndex);
/**
* Returns range of values from <code>fromIndex</code> to <code>toIndex</code> index including.
* Indexes are zero based. <code>-1</code> means the last element, <code>-2</code> means penultimate and so on.
*
* @param fromIndex - start index
* @param toIndex - end index
* @return
*/
Single<List<V>> range(int fromIndex, int toIndex);
}

@ -235,6 +235,20 @@ public class RedissonListMultimapTest extends BaseTest {
assertThat(map.containsEntry(new SimpleKey("0"), new SimpleValue("2"))).isFalse();
}
@Test
public void testRange() {
RListMultimap<Integer, Integer> map = redisson.getListMultimap("test1");
map.put(1, 1);
map.put(1, 2);
map.put(1, 3);
map.put(1, 4);
map.put(1, 5);
assertThat(map.get(1).range(1)).containsExactly(1, 2);
assertThat(map.get(1).range(1, 3)).containsExactly(2, 3, 4);
}
@Test
public void testRemove() {
RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("test1");

@ -34,6 +34,23 @@ public class RedissonListTest extends BaseTest {
assertThat(list.get(1, 2, 3)).containsSequence(2, 3, 4);
}
@Test
public void testRange() {
RList<Integer> list = redisson.getList("list", IntegerCodec.INSTANCE);
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
assertThat(list.range(1)).containsExactly(1, 2);
assertThat(list.range(1, 3)).containsExactly(2, 3, 4);
list.delete();
assertThat(list.range(0, 2)).isEmpty();
}
@Test
public void testSortOrder() {
RList<Integer> list = redisson.getList("list", IntegerCodec.INSTANCE);

Loading…
Cancel
Save