Feature - firstEntry() and lastEntry() methods added to RScoredSortedSet object. #5074

pull/5079/head
Nikita Koksharov 2 years ago
parent 21ce123928
commit de6ec8bec3

@ -557,6 +557,16 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
return commandExecutor.readAsync(getRawName(), codec, RedisCommands.ZRANGE_SINGLE, getRawName(), 0, 0);
}
@Override
public ScoredEntry<V> firstEntry() {
return get(firstEntryAsync());
}
@Override
public RFuture<ScoredEntry<V>> firstEntryAsync() {
return commandExecutor.readAsync(getRawName(), codec, RedisCommands.ZRANGE_SINGLE_ENTRY, getRawName(), 0, 0, "WITHSCORES");
}
@Override
public V last() {
return get(lastAsync());
@ -567,6 +577,16 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
return commandExecutor.readAsync(getRawName(), codec, RedisCommands.ZRANGE_SINGLE, getRawName(), -1, -1);
}
@Override
public ScoredEntry<V> lastEntry() {
return get(lastEntryAsync());
}
@Override
public RFuture<ScoredEntry<V>> lastEntryAsync() {
return commandExecutor.readAsync(getRawName(), codec, RedisCommands.ZRANGE_SINGLE_ENTRY, getRawName(), -1, -1, "WITHSCORES");
}
@Override
public Double firstScore() {
return get(firstScoreAsync());

@ -364,6 +364,13 @@ public interface RScoredSortedSet<V> extends RScoredSortedSetAsync<V>, Iterable<
*/
V first();
/**
* Returns the head entry (value and its score) or {@code null} if this sorted set is empty.
*
* @return the head entry or {@code null} if this sorted set is empty
*/
ScoredEntry<V> firstEntry();
/**
* Returns the tail element or {@code null} if this sorted set is empty.
*
@ -371,6 +378,13 @@ public interface RScoredSortedSet<V> extends RScoredSortedSetAsync<V>, Iterable<
*/
V last();
/**
* Returns the tail entry (value and its score) or {@code null} if this sorted set is empty.
*
* @return the tail entry or {@code null} if this sorted set is empty
*/
ScoredEntry<V> lastEntry();
/**
* Returns score of the tail element or returns {@code null} if this sorted set is empty.
*

@ -325,6 +325,13 @@ public interface RScoredSortedSetAsync<V> extends RExpirableAsync, RSortableAsyn
*/
RFuture<V> firstAsync();
/**
* Returns the head entry (value and its score) or {@code null} if this sorted set is empty.
*
* @return the head entry or {@code null} if this sorted set is empty
*/
RFuture<ScoredEntry<V>> firstEntryAsync();
/**
* Returns the tail element or {@code null} if this sorted set is empty.
*
@ -332,6 +339,13 @@ public interface RScoredSortedSetAsync<V> extends RExpirableAsync, RSortableAsyn
*/
RFuture<V> lastAsync();
/**
* Returns the tail entry (value and its score) or {@code null} if this sorted set is empty.
*
* @return the tail entry or {@code null} if this sorted set is empty
*/
RFuture<ScoredEntry<V>> lastEntryAsync();
/**
* Returns score of the head element or returns {@code null} if this sorted set is empty.
*

@ -314,6 +314,13 @@ public interface RScoredSortedSetReactive<V> extends RExpirableReactive, RSortab
*/
Mono<V> first();
/**
* Returns the head entry (value and its score) or {@code null} if this sorted set is empty.
*
* @return the head entry or {@code null} if this sorted set is empty
*/
Mono<ScoredEntry<V>> firstEntry();
/**
* Returns the tail element or {@code null} if this sorted set is empty.
*
@ -321,6 +328,13 @@ public interface RScoredSortedSetReactive<V> extends RExpirableReactive, RSortab
*/
Mono<V> last();
/**
* Returns the tail entry (value and its score) or {@code null} if this sorted set is empty.
*
* @return the tail entry or {@code null} if this sorted set is empty
*/
Mono<ScoredEntry<V>> lastEntry();
/**
* Returns score of the head element or returns {@code null} if this sorted set is empty.
*

@ -315,6 +315,13 @@ public interface RScoredSortedSetRx<V> extends RExpirableRx, RSortableRx<Set<V>>
*/
Maybe<V> first();
/**
* Returns the head entry (value and its score) or {@code null} if this sorted set is empty.
*
* @return the head entry or {@code null} if this sorted set is empty
*/
Maybe<ScoredEntry<V>> firstEntry();
/**
* Returns the tail element or {@code null} if this sorted set is empty.
*
@ -322,6 +329,13 @@ public interface RScoredSortedSetRx<V> extends RExpirableRx, RSortableRx<Set<V>>
*/
Maybe<V> last();
/**
* Returns the tail entry (value and its score) or {@code null} if this sorted set is empty.
*
* @return the tail entry or {@code null} if this sorted set is empty
*/
Maybe<ScoredEntry<V>> lastEntry();
/**
* Returns score of the head element or returns {@code null} if this sorted set is empty.
*

@ -111,6 +111,7 @@ public interface RedisCommands {
RedisCommand<Integer> ZREVRANK_INT = new RedisCommand<Integer>("ZREVRANK", new IntegerReplayConvertor());
RedisCommand<RankedEntry<?>> ZREVRANK_ENTRY = new RedisCommand<>("ZREVRANK", new RankedEntryDecoder());
RedisCommand<Object> ZRANGE_SINGLE = new RedisCommand<Object>("ZRANGE", new ListFirstObjectDecoder());
RedisCommand<Object> ZRANGE_SINGLE_ENTRY = new RedisCommand<>("ZRANGE", new ListFirstObjectDecoder(new ScoredSortedSetReplayDecoder()));
RedisStrictCommand<Double> ZRANGE_SINGLE_SCORE = new RedisStrictCommand<Double>("ZRANGE", new ObjectFirstScoreReplayDecoder());
RedisCommand<List<Object>> ZRANGE = new RedisCommand<List<Object>>("ZRANGE", new ObjectListReplayDecoder<Object>());
RedisCommand<Integer> ZRANGESTORE = new RedisCommand<>("ZRANGESTORE", new IntegerReplayConvertor());

@ -27,6 +27,19 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class RedissonScoredSortedSetTest extends BaseTest {
@Test
public void testEntries() {
RScoredSortedSet<String> set = redisson.getScoredSortedSet("test");
set.add(1.1, "v1");
set.add(1.2, "v2");
set.add(1.3, "v3");
ScoredEntry<String> s = set.firstEntry();
assertThat(s).isEqualTo(new ScoredEntry<>(1.1, "v1"));
ScoredEntry<String> s2 = set.lastEntry();
assertThat(s2).isEqualTo(new ScoredEntry<>(1.3, "v3"));
}
@Test
public void testPollEntryDuration() {
RScoredSortedSet<String> set = redisson.getScoredSortedSet("test");

Loading…
Cancel
Save