Add popFirst and popLast methods to RedisZSet.
See #2007 Original Pull Request: #2088
This commit is contained in:
committed by
Christoph Strobl
parent
0f2039d5a0
commit
739b917922
@@ -19,6 +19,7 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.redis.connection.DataType;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
@@ -380,6 +381,38 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.support.collections.RedisZSet#popFirst()
|
||||
*/
|
||||
@Override
|
||||
public E popFirst() {
|
||||
|
||||
TypedTuple<E> tuple = boundZSetOps.popMin();
|
||||
|
||||
if (tuple != null) {
|
||||
return tuple.getValue();
|
||||
}
|
||||
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.support.collections.RedisZSet#popFirst(long, java.util.concurrent.TimeUnit)
|
||||
*/
|
||||
@Override
|
||||
public E popFirst(long timeout, TimeUnit unit) {
|
||||
|
||||
TypedTuple<E> tuple = boundZSetOps.popMin(timeout, unit);
|
||||
|
||||
if (tuple != null) {
|
||||
return tuple.getValue();
|
||||
}
|
||||
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.support.collections.RedisZSet#last()
|
||||
@@ -397,6 +430,38 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.support.collections.RedisZSet#popLast()
|
||||
*/
|
||||
@Override
|
||||
public E popLast() {
|
||||
|
||||
TypedTuple<E> tuple = boundZSetOps.popMax();
|
||||
|
||||
if (tuple != null) {
|
||||
return tuple.getValue();
|
||||
}
|
||||
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.support.collections.RedisZSet#popLast(long, java.util.concurrent.TimeUnit)
|
||||
*/
|
||||
@Override
|
||||
public E popLast(long timeout, TimeUnit unit) {
|
||||
|
||||
TypedTuple<E> tuple = boundZSetOps.popMax(timeout, unit);
|
||||
|
||||
if (tuple != null) {
|
||||
return tuple.getValue();
|
||||
}
|
||||
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.support.collections.RedisZSet#rank(java.lang.Object)
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
|
||||
@@ -217,6 +218,28 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
|
||||
*/
|
||||
E first();
|
||||
|
||||
/**
|
||||
* Removes the first (lowest) object at the top of this sorted set and returns that object as the value of this
|
||||
* function.
|
||||
*
|
||||
* @return the first (lowest) element currently in this sorted set.
|
||||
* @throws NoSuchElementException sorted set is empty.
|
||||
* @since 2.6
|
||||
*/
|
||||
E popFirst();
|
||||
|
||||
/**
|
||||
* Removes the first (lowest) object at the top of this sorted set and returns that object as the value of this
|
||||
* function. <b>Blocks connection</b> until element available or {@code timeout} reached.
|
||||
*
|
||||
* @param timeout
|
||||
* @param unit must not be {@literal null}.
|
||||
* @return the first (lowest) element currently in this sorted set.
|
||||
* @throws NoSuchElementException sorted set is empty.
|
||||
* @since 2.6
|
||||
*/
|
||||
E popFirst(long timeout, TimeUnit unit);
|
||||
|
||||
/**
|
||||
* Returns the last (highest) element currently in this sorted set.
|
||||
*
|
||||
@@ -225,6 +248,28 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
|
||||
*/
|
||||
E last();
|
||||
|
||||
/**
|
||||
* Removes the last (highest) object at the top of this sorted set and returns that object as the value of this
|
||||
* function.
|
||||
*
|
||||
* @return the last (highest) element currently in this sorted set.
|
||||
* @throws NoSuchElementException sorted set is empty.
|
||||
* @since 2.6
|
||||
*/
|
||||
E popLast();
|
||||
|
||||
/**
|
||||
* Removes the last (highest) object at the top of this sorted set and returns that object as the value of this
|
||||
* function. <b>Blocks connection</b> until element available or {@code timeout} reached.
|
||||
*
|
||||
* @param timeout
|
||||
* @param unit must not be {@literal null}.
|
||||
* @return the last (highest) element currently in this sorted set.
|
||||
* @throws NoSuchElementException sorted set is empty.
|
||||
* @since 2.6
|
||||
*/
|
||||
E popLast(long timeout, TimeUnit unit);
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
* @return
|
||||
|
||||
Reference in New Issue
Block a user