+ add Queue support for the the redis list
This commit is contained in:
@@ -19,6 +19,8 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Queue;
|
||||
|
||||
import org.springframework.datastore.redis.connection.RedisCommands;
|
||||
|
||||
@@ -27,7 +29,7 @@ import org.springframework.datastore.redis.connection.RedisCommands;
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class DefaultRedisList extends AbstractRedisCollection implements RedisList {
|
||||
public class DefaultRedisList extends AbstractRedisCollection implements RedisList, Queue<String> {
|
||||
|
||||
public DefaultRedisList(String key, RedisCommands commands) {
|
||||
super(key, commands);
|
||||
@@ -144,4 +146,43 @@ public class DefaultRedisList extends AbstractRedisCollection implements RedisLi
|
||||
public List<String> subList(int fromIndex, int toIndex) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String element() {
|
||||
String value = peek();
|
||||
if (value == null)
|
||||
throw new NoSuchElementException();
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean offer(String e) {
|
||||
commands.lPush(key, e);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String peek() {
|
||||
return commands.lIndex(key, 0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String poll() {
|
||||
return commands.lPop(key);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String remove() {
|
||||
String value = poll();
|
||||
if (value == null)
|
||||
throw new NoSuchElementException();
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user