Feature - add revRangeTo() method to RScoredSortedSet object #3362

pull/3384/head
Nikita Koksharov 4 years ago
parent 5416a81137
commit 4722679004

@ -1319,6 +1319,40 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
return get(rangeToAsync(destName, startScore, startScoreInclusive, endScore, endScoreInclusive, offset, count));
}
@Override
public int revRangeTo(String destName, int startIndex, int endIndex) {
return get(revRangeToAsync(destName, startIndex, endIndex));
}
@Override
public int revRangeTo(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive) {
return get(revRangeToAsync(destName, startScore, startScoreInclusive, endScore, endScoreInclusive));
}
@Override
public int revRangeTo(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count) {
return get(revRangeToAsync(destName, startScore, startScoreInclusive, endScore, endScoreInclusive, offset, count));
}
@Override
public RFuture<Integer> revRangeToAsync(String destName, int startIndex, int endIndex) {
return commandExecutor.writeAsync(getName(), codec, RedisCommands.ZRANGESTORE, destName, getName(), startIndex, endIndex, "REV");
}
@Override
public RFuture<Integer> revRangeToAsync(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive) {
String startValue = value(startScore, startScoreInclusive);
String endValue = value(endScore, endScoreInclusive);
return commandExecutor.writeAsync(getName(), codec, RedisCommands.ZRANGESTORE, destName, getName(), startValue, endValue, "BYSCORE", "REV");
}
@Override
public RFuture<Integer> revRangeToAsync(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count) {
String startValue = value(startScore, startScoreInclusive);
String endValue = value(endScore, endScoreInclusive);
return commandExecutor.writeAsync(getName(), codec, RedisCommands.ZRANGESTORE, destName, getName(), startValue, endValue, "BYSCORE", "REV", "LIMIT", offset, count);
}
@Override
public RFuture<Integer> rangeToAsync(String destName, int startIndex, int endIndex) {
return commandExecutor.writeAsync(getName(), codec, RedisCommands.ZRANGESTORE, destName, getName(), startIndex, endIndex);

@ -583,6 +583,56 @@ public interface RScoredSortedSet<V> extends RScoredSortedSetAsync<V>, Iterable<
*/
int rangeTo(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count);
/**
* Stores to defined ScoredSortedSet values in reversed order by rank range. Indexes are zero based.
* <code>-1</code> means the highest score, <code>-2</code> means the second highest score.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param startIndex - start index
* @param endIndex - end index
* @return elements
*/
int revRangeTo(String destName, int startIndex, int endIndex);
/**
* Stores to defined ScoredSortedSet values in reversed order between <code>startScore</code> and <code>endScore</code>.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param startScore - start score.
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
* @param startScoreInclusive - start score inclusive
* @param endScore - end score
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
*
* @param endScoreInclusive - end score inclusive
* @return values
*/
int revRangeTo(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive);
/**
* Stores to defined ScoredSortedSet values in reversed order between <code>startScore</code> and <code>endScore</code>.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param startScore - start score.
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
* @param startScoreInclusive - start score inclusive
* @param endScore - end score
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
*
* @param endScoreInclusive - end score inclusive
* @param offset - offset of sorted data
* @param count - amount of sorted data
* @return values
*/
int revRangeTo(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count);
/**
* Returns values by rank range. Indexes are zero based.
* <code>-1</code> means the highest score, <code>-2</code> means the second highest score.

@ -448,6 +448,54 @@ public interface RScoredSortedSetAsync<V> extends RExpirableAsync, RSortableAsyn
*/
RFuture<Integer> rangeToAsync(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count);
/**
* Stores to defined ScoredSortedSet values in reversed order by rank range. Indexes are zero based.
* <code>-1</code> means the highest score, <code>-2</code> means the second highest score.
*
* @param startIndex - start index
* @param endIndex - end index
* @return elements
*/
RFuture<Integer> revRangeToAsync(String destName, int startIndex, int endIndex);
/**
* Stores to defined ScoredSortedSet values in reversed order between <code>startScore</code> and <code>endScore</code>.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param startScore - start score.
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
* @param startScoreInclusive - start score inclusive
* @param endScore - end score
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
*
* @param endScoreInclusive - end score inclusive
* @return values
*/
RFuture<Integer> revRangeToAsync(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive);
/**
* Stores to defined ScoredSortedSet values in reversed order between <code>startScore</code> and <code>endScore</code>.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param startScore - start score.
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
* @param startScoreInclusive - start score inclusive
* @param endScore - end score
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
*
* @param endScoreInclusive - end score inclusive
* @param offset - offset of sorted data
* @param count - amount of sorted data
* @return values
*/
RFuture<Integer> revRangeToAsync(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count);
/**
* Returns values by rank range. Indexes are zero based.
* <code>-1</code> means the highest score, <code>-2</code> means the second highest score.

@ -667,6 +667,56 @@ public interface RScoredSortedSetReactive<V> extends RExpirableReactive, RSortab
*/
Mono<Integer> rangeTo(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count);
/**
* Stores to defined ScoredSortedSet values in reversed order by rank range. Indexes are zero based.
* <code>-1</code> means the highest score, <code>-2</code> means the second highest score.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param startIndex - start index
* @param endIndex - end index
* @return elements
*/
Mono<Integer> revRangeTo(String destName, int startIndex, int endIndex);
/**
* Stores to defined ScoredSortedSet values in reversed order between <code>startScore</code> and <code>endScore</code>.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param startScore - start score.
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
* @param startScoreInclusive - start score inclusive
* @param endScore - end score
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
*
* @param endScoreInclusive - end score inclusive
* @return values
*/
Mono<Integer> revRangeTo(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive);
/**
* Stores to defined ScoredSortedSet values in reversed order between <code>startScore</code> and <code>endScore</code>.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param startScore - start score.
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
* @param startScoreInclusive - start score inclusive
* @param endScore - end score
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
*
* @param endScoreInclusive - end score inclusive
* @param offset - offset of sorted data
* @param count - amount of sorted data
* @return values
*/
Mono<Integer> revRangeTo(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count);
/**
* Intersect provided ScoredSortedSets
* and store result to current ScoredSortedSet

@ -474,6 +474,56 @@ public interface RScoredSortedSetRx<V> extends RExpirableRx, RSortableRx<Set<V>>
*/
Single<Integer> rangeTo(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count);
/**
* Stores to defined ScoredSortedSet values in reversed order by rank range. Indexes are zero based.
* <code>-1</code> means the highest score, <code>-2</code> means the second highest score.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param startIndex - start index
* @param endIndex - end index
* @return elements
*/
Single<Integer> revRangeTo(String destName, int startIndex, int endIndex);
/**
* Stores to defined ScoredSortedSet values in reversed order between <code>startScore</code> and <code>endScore</code>.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param startScore - start score.
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
* @param startScoreInclusive - start score inclusive
* @param endScore - end score
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
*
* @param endScoreInclusive - end score inclusive
* @return values
*/
Single<Integer> revRangeTo(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive);
/**
* Stores to defined ScoredSortedSet values in reversed order between <code>startScore</code> and <code>endScore</code>.
* <p>
* Requires <b>Redis 6.2.0 and higher.</b>
*
* @param startScore - start score.
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
* @param startScoreInclusive - start score inclusive
* @param endScore - end score
* Use <code>Double.POSITIVE_INFINITY</code> or <code>Double.NEGATIVE_INFINITY</code>
* to define infinity numbers
*
* @param endScoreInclusive - end score inclusive
* @param offset - offset of sorted data
* @param count - amount of sorted data
* @return values
*/
Single<Integer> revRangeTo(String destName, double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive, int offset, int count);
/**
* Returns values by rank range. Indexes are zero based.
* <code>-1</code> means the highest score, <code>-2</code> means the second highest score.

@ -1390,7 +1390,20 @@ public class RedissonScoredSortedSetTest extends BaseTest {
set1.rangeTo("simple2", 0, 3);
RScoredSortedSet<Integer> set2 = redisson.getScoredSortedSet("simple2");
assertThat(set2.readAll()).containsOnly(0, 1, 2, 3, 4);
assertThat(set2.readAll()).containsOnly(0, 1, 2, 3);
}
@Test
public void testRevRange() {
RScoredSortedSet<Integer> set1 = redisson.getScoredSortedSet("simple1");
for (int i = 0; i < 10; i++) {
set1.add(i, i);
}
set1.revRangeTo("simple2", 3, true, 0, false);
RScoredSortedSet<Integer> set2 = redisson.getScoredSortedSet("simple2");
assertThat(set2.readAll()).containsOnly(3, 2, 1);
}
@Test

Loading…
Cancel
Save