iterators infinity scroll fixed. #277

pull/282/head
Nikita 9 years ago
parent 6065a7a8e0
commit 3f8e4d765a

@ -81,6 +81,7 @@ public class RedissonKeys implements RKeys {
private Iterator<String> createKeysIterator(final int slot, final String pattern) {
return new Iterator<String>() {
private List<String> firstValues;
private Iterator<String> iter;
private long iterPos;
@ -91,6 +92,11 @@ public class RedissonKeys implements RKeys {
public boolean hasNext() {
if (iter == null || !iter.hasNext()) {
ListScanResult<String> res = scanIterator(slot, iterPos, pattern);
if (iterPos == 0 && firstValues == null) {
firstValues = res.getValues();
} else if (res.getValues().equals(firstValues)) {
return false;
}
iter = res.getValues().iterator();
iterPos = res.getPos();
}

@ -45,7 +45,7 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
@Override
public Future<Integer> removeRangeHeadByLexAsync(String toElement, boolean toInclusive) {
String toValue = value(toElement, toInclusive);
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZREMRANGEBYLEX, getName(), "-", toValue);
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZREMRANGEBYLEX, getName(), "-", toValue);
}
@Override
@ -56,7 +56,7 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
@Override
public Future<Integer> removeRangeTailByLexAsync(String fromElement, boolean fromInclusive) {
String fromValue = value(fromElement, fromInclusive);
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZREMRANGEBYLEX, getName(), fromValue, "+");
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZREMRANGEBYLEX, getName(), fromValue, "+");
}
@Override
@ -64,7 +64,7 @@ public class RedissonLexSortedSet extends RedissonScoredSortedSet<String> implem
String fromValue = value(fromElement, fromInclusive);
String toValue = value(toElement, toInclusive);
return commandExecutor.readAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZREMRANGEBYLEX, getName(), fromValue, toValue);
return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZREMRANGEBYLEX, getName(), fromValue, toValue);
}
@Override

@ -300,6 +300,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
private Iterator<Map.Entry<K, V>> iterator() {
return new Iterator<Map.Entry<K, V>>() {
private Map<K, V> firstValues;
private Iterator<Map.Entry<K, V>> iter;
private long iterPos = 0;
private RedisClient client;
@ -312,6 +313,11 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
if (iter == null || !iter.hasNext()) {
MapScanResult<Object, V> res = scanIterator(client, iterPos);
client = res.getRedisClient();
if (iterPos == 0 && firstValues == null) {
firstValues = (Map<K, V>) res.getMap();
} else if (res.getMap().equals(firstValues)) {
return false;
}
iter = ((Map<K, V>)res.getMap()).entrySet().iterator();
iterPos = res.getPos();
}

@ -80,7 +80,7 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
}
public Future<Integer> removeRangeByRankAsync(int startIndex, int endIndex) {
return commandExecutor.readAsync(getName(), codec, RedisCommands.ZREMRANGEBYRANK, getName(), startIndex, endIndex);
return commandExecutor.writeAsync(getName(), codec, RedisCommands.ZREMRANGEBYRANK, getName(), startIndex, endIndex);
}
public int removeRangeByScore(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive) {
@ -90,7 +90,7 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
public Future<Integer> removeRangeByScoreAsync(double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive) {
String startValue = value(BigDecimal.valueOf(startScore).toPlainString(), startScoreInclusive);
String endValue = value(BigDecimal.valueOf(endScore).toPlainString(), endScoreInclusive);
return commandExecutor.readAsync(getName(), codec, RedisCommands.ZREMRANGEBYSCORE, getName(), startValue, endValue);
return commandExecutor.writeAsync(getName(), codec, RedisCommands.ZREMRANGEBYSCORE, getName(), startValue, endValue);
}
private String value(String element, boolean inclusive) {
@ -163,6 +163,7 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
public Iterator<V> iterator() {
return new Iterator<V>() {
private List<V> firstValues;
private Iterator<V> iter;
private RedisClient client;
private long iterPos;
@ -175,6 +176,11 @@ public class RedissonScoredSortedSet<V> extends RedissonExpirable implements RSc
if (iter == null || !iter.hasNext()) {
ListScanResult<V> res = scanIterator(client, iterPos);
client = res.getRedisClient();
if (iterPos == 0 && firstValues == null) {
firstValues = res.getValues();
} else if (res.getValues().equals(firstValues)) {
return false;
}
iter = res.getValues().iterator();
iterPos = res.getPos();
}

@ -84,6 +84,7 @@ public class RedissonSet<V> extends RedissonExpirable implements RSet<V> {
public Iterator<V> iterator() {
return new Iterator<V>() {
private List<V> firstValues;
private Iterator<V> iter;
private RedisClient client;
private long iterPos;
@ -96,6 +97,11 @@ public class RedissonSet<V> extends RedissonExpirable implements RSet<V> {
if (iter == null || !iter.hasNext()) {
ListScanResult<V> res = scanIterator(client, iterPos);
client = res.getRedisClient();
if (iterPos == 0 && firstValues == null) {
firstValues = res.getValues();
} else if (res.getValues().equals(firstValues)) {
return false;
}
iter = res.getValues().iterator();
iterPos = res.getPos();
}

Loading…
Cancel
Save