DATAKV-72
+ add missing rangeWithScores and reverserRangeWithScores ops for ZSets
This commit is contained in:
@@ -516,16 +516,32 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
return delegate.zRangeByScore(key, min, max);
|
||||
}
|
||||
|
||||
public Set<Tuple> zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) {
|
||||
return delegate.zRangeByScoreWithScore(key, min, max, offset, count);
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
|
||||
return delegate.zRangeByScoreWithScores(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public Set<Tuple> zRangeByScoreWithScore(byte[] key, double min, double max) {
|
||||
return delegate.zRangeByScoreWithScore(key, min, max);
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max) {
|
||||
return delegate.zRangeByScoreWithScores(key, min, max);
|
||||
}
|
||||
|
||||
public Set<Tuple> zRangeWithScore(byte[] key, long start, long end) {
|
||||
return delegate.zRangeWithScore(key, start, end);
|
||||
public Set<Tuple> zRangeWithScores(byte[] key, long start, long end) {
|
||||
return delegate.zRangeWithScores(key, start, end);
|
||||
}
|
||||
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, double min, double max, long offset, long count) {
|
||||
return delegate.zRevRangeByScore(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, double min, double max) {
|
||||
return delegate.zRevRangeByScore(key, min, max);
|
||||
}
|
||||
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
|
||||
return delegate.zRevRangeByScoreWithScores(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max) {
|
||||
return delegate.zRevRangeByScoreWithScores(key, min, max);
|
||||
}
|
||||
|
||||
public Long zRank(byte[] key, byte[] value) {
|
||||
@@ -548,8 +564,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
return delegate.zRevRange(key, start, end);
|
||||
}
|
||||
|
||||
public Set<Tuple> zRevRangeWithScore(byte[] key, long start, long end) {
|
||||
return delegate.zRevRangeWithScore(key, start, end);
|
||||
public Set<Tuple> zRevRangeWithScores(byte[] key, long start, long end) {
|
||||
return delegate.zRevRangeWithScores(key, start, end);
|
||||
}
|
||||
|
||||
public Long zRevRank(byte[] key, byte[] value) {
|
||||
@@ -1058,18 +1074,18 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<StringTuple> zRangeByScoreWithScore(String key, double min, double max, long offset, long count) {
|
||||
return deserializeTuple(delegate.zRangeByScoreWithScore(serialize(key), min, max, offset, count));
|
||||
public Set<StringTuple> zRangeByScoreWithScores(String key, double min, double max, long offset, long count) {
|
||||
return deserializeTuple(delegate.zRangeByScoreWithScores(serialize(key), min, max, offset, count));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<StringTuple> zRangeByScoreWithScore(String key, double min, double max) {
|
||||
return deserializeTuple(delegate.zRangeByScoreWithScore(serialize(key), min, max));
|
||||
public Set<StringTuple> zRangeByScoreWithScores(String key, double min, double max) {
|
||||
return deserializeTuple(delegate.zRangeByScoreWithScores(serialize(key), min, max));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<StringTuple> zRangeWithScore(String key, long start, long end) {
|
||||
return deserializeTuple(delegate.zRangeWithScore(serialize(key), start, end));
|
||||
public Set<StringTuple> zRangeWithScores(String key, long start, long end) {
|
||||
return deserializeTuple(delegate.zRangeWithScores(serialize(key), start, end));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1098,8 +1114,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<StringTuple> zRevRangeWithScore(String key, long start, long end) {
|
||||
return deserializeTuple(delegate.zRevRangeWithScore(serialize(key), start, end));
|
||||
public Set<StringTuple> zRevRangeWithScores(String key, long start, long end) {
|
||||
return deserializeTuple(delegate.zRevRangeWithScores(serialize(key), start, end));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -54,19 +54,27 @@ public interface RedisZSetCommands {
|
||||
|
||||
Set<byte[]> zRange(byte[] key, long begin, long end);
|
||||
|
||||
Set<Tuple> zRangeWithScore(byte[] key, long begin, long end);
|
||||
|
||||
Set<byte[]> zRevRange(byte[] key, long begin, long end);
|
||||
|
||||
Set<Tuple> zRevRangeWithScore(byte[] key, long begin, long end);
|
||||
Set<Tuple> zRangeWithScores(byte[] key, long begin, long end);
|
||||
|
||||
Set<byte[]> zRangeByScore(byte[] key, double min, double max);
|
||||
|
||||
Set<Tuple> zRangeByScoreWithScore(byte[] key, double min, double max);
|
||||
Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max);
|
||||
|
||||
Set<byte[]> zRangeByScore(byte[] key, double min, double max, long offset, long count);
|
||||
|
||||
Set<Tuple> zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count);
|
||||
Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count);
|
||||
|
||||
Set<byte[]> zRevRange(byte[] key, long begin, long end);
|
||||
|
||||
Set<Tuple> zRevRangeWithScores(byte[] key, long begin, long end);
|
||||
|
||||
Set<byte[]> zRevRangeByScore(byte[] key, double min, double max);
|
||||
|
||||
Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max);
|
||||
|
||||
Set<byte[]> zRevRangeByScore(byte[] key, double min, double max, long offset, long count);
|
||||
|
||||
Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count);
|
||||
|
||||
Long zCount(byte[] key, double min, double max);
|
||||
|
||||
|
||||
@@ -181,19 +181,19 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
|
||||
Set<String> zRange(String key, long start, long end);
|
||||
|
||||
Set<StringTuple> zRangeWithScore(String key, long start, long end);
|
||||
Set<StringTuple> zRangeWithScores(String key, long start, long end);
|
||||
|
||||
Set<String> zRevRange(String key, long start, long end);
|
||||
|
||||
Set<StringTuple> zRevRangeWithScore(String key, long start, long end);
|
||||
Set<StringTuple> zRevRangeWithScores(String key, long start, long end);
|
||||
|
||||
Set<String> zRangeByScore(String key, double min, double max);
|
||||
|
||||
Set<StringTuple> zRangeByScoreWithScore(String key, double min, double max);
|
||||
Set<StringTuple> zRangeByScoreWithScores(String key, double min, double max);
|
||||
|
||||
Set<String> zRangeByScore(String key, double min, double max, long offset, long count);
|
||||
|
||||
Set<StringTuple> zRangeByScoreWithScore(String key, double min, double max, long offset, long count);
|
||||
Set<StringTuple> zRangeByScoreWithScores(String key, double min, double max, long offset, long count);
|
||||
|
||||
Long zCount(String key, double min, double max);
|
||||
|
||||
|
||||
@@ -1740,7 +1740,7 @@ public class JedisConnection implements RedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeWithScore(byte[] key, long start, long end) {
|
||||
public Set<Tuple> zRangeWithScores(byte[] key, long start, long end) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
transaction.zrangeWithScores(key, (int) start, (int) end);
|
||||
@@ -1773,7 +1773,7 @@ public class JedisConnection implements RedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeByScoreWithScore(byte[] key, double min, double max) {
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
@@ -1789,16 +1789,17 @@ public class JedisConnection implements RedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeWithScore(byte[] key, long start, long end) {
|
||||
public Set<Tuple> zRevRangeWithScores(byte[] key, long start, long end) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
if (isPipelined()) {
|
||||
pipeline.zrangeByScoreWithScores(key, (int) start, (int) end);
|
||||
transaction.zrevrangeWithScores(key, (int) start, (int) end);
|
||||
return null;
|
||||
}
|
||||
return JedisUtils.convertJedisTuple(jedis.zrangeByScoreWithScores(key, (int) start, (int) end));
|
||||
if (isPipelined()) {
|
||||
pipeline.zrevrangeWithScores(key, (int) start, (int) end);
|
||||
return null;
|
||||
}
|
||||
return JedisUtils.convertJedisTuple(jedis.zrevrangeWithScores(key, (int) start, (int) end));
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
@@ -1821,7 +1822,7 @@ public class JedisConnection implements RedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) {
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
@@ -1836,6 +1837,66 @@ public class JedisConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, double min, double max, long offset, long count) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
if (isPipelined()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, double min, double max) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
if (isPipelined()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
if (isPipelined()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max) {
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
if (isPipelined()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long zRank(byte[] key, byte[] value) {
|
||||
try {
|
||||
|
||||
@@ -886,9 +886,8 @@ public class JredisConnection implements RedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeWithScore(byte[] key, long start, long end) {
|
||||
public Set<Tuple> zRangeWithScores(byte[] key, long start, long end) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -901,7 +900,7 @@ public class JredisConnection implements RedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeByScoreWithScore(byte[] key, double min, double max) {
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -911,7 +910,27 @@ public class JredisConnection implements RedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) {
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, double min, double max, long offset, long count) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, double min, double max) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@@ -961,7 +980,7 @@ public class JredisConnection implements RedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeWithScore(byte[] key, long start, long end) {
|
||||
public Set<Tuple> zRevRangeWithScores(byte[] key, long start, long end) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@@ -1547,7 +1547,7 @@ public class RjcConnection implements RedisConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeWithScore(byte[] key, long start, long end) {
|
||||
public Set<Tuple> zRangeWithScores(byte[] key, long start, long end) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
try {
|
||||
|
||||
@@ -1578,41 +1578,6 @@ public class RjcConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeByScoreWithScore(byte[] key, double min, double max) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
String minString = Double.toString(min);
|
||||
String maxString = Double.toString(max);
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline.zrangeByScoreWithScores(stringKey, minString, maxString);
|
||||
return null;
|
||||
}
|
||||
return RjcUtils.convertElementScore(session.zrangeByScoreWithScores(stringKey, minString, maxString));
|
||||
} catch (Exception ex) {
|
||||
throw convertRjcAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeWithScore(byte[] key, long start, long end) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
String minString = Long.toString(start);
|
||||
String maxString = Long.toString(end);
|
||||
|
||||
try {
|
||||
|
||||
if (isPipelined()) {
|
||||
pipeline.zrangeByScoreWithScores(stringKey, minString, maxString);
|
||||
return null;
|
||||
}
|
||||
return RjcUtils.convertElementScore(session.zrangeByScoreWithScores(stringKey, minString, maxString));
|
||||
} catch (Exception ex) {
|
||||
throw convertRjcAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, double min, double max, long offset, long count) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
@@ -1631,8 +1596,79 @@ public class RjcConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeByScoreWithScore(byte[] key, double min, double max, long offset, long count) {
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, double min, double max, long offset, long count) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
String minString = Double.toString(min);
|
||||
String maxString = Double.toString(max);
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline.zrevrangeByScore(stringKey, minString, maxString, (int) offset, (int) count);
|
||||
return null;
|
||||
}
|
||||
return RjcUtils.convertToSet(session.zrevrangeByScore(stringKey, minString, maxString, (int) offset,
|
||||
(int) count));
|
||||
} catch (Exception ex) {
|
||||
throw convertRjcAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRevRangeByScore(byte[] key, double min, double max) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
String minString = Double.toString(min);
|
||||
String maxString = Double.toString(max);
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline.zrevrangeByScore(stringKey, minString, maxString);
|
||||
return null;
|
||||
}
|
||||
return RjcUtils.convertToSet(session.zrevrangeByScore(stringKey, minString, maxString));
|
||||
} catch (Exception ex) {
|
||||
throw convertRjcAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
String minString = Double.toString(min);
|
||||
String maxString = Double.toString(max);
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline.zrangeByScoreWithScores(stringKey, minString, maxString);
|
||||
return null;
|
||||
}
|
||||
return RjcUtils.convertElementScore(session.zrangeByScoreWithScores(stringKey, minString, maxString));
|
||||
} catch (Exception ex) {
|
||||
throw convertRjcAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeWithScores(byte[] key, long start, long end) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
String minString = Long.toString(start);
|
||||
String maxString = Long.toString(end);
|
||||
|
||||
try {
|
||||
|
||||
if (isPipelined()) {
|
||||
pipeline.zrevrangeByScoreWithScores(stringKey, minString, maxString);
|
||||
return null;
|
||||
}
|
||||
return RjcUtils.convertElementScore(session.zrevrangeByScoreWithScores(stringKey, minString, maxString));
|
||||
} catch (Exception ex) {
|
||||
throw convertRjcAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
String minString = Double.toString(min);
|
||||
String maxString = Double.toString(max);
|
||||
@@ -1649,6 +1685,44 @@ public class RjcConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
String minString = Double.toString(min);
|
||||
String maxString = Double.toString(max);
|
||||
|
||||
try {
|
||||
|
||||
if (isPipelined()) {
|
||||
pipeline.zrevrangeByScoreWithScores(stringKey, minString, maxString, (int) offset, (int) count);
|
||||
return null;
|
||||
}
|
||||
return RjcUtils.convertElementScore(session.zrevrangeByScoreWithScores(stringKey, minString, maxString,
|
||||
(int) offset, (int) count));
|
||||
} catch (Exception ex) {
|
||||
throw convertRjcAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
String minString = Double.toString(min);
|
||||
String maxString = Double.toString(max);
|
||||
|
||||
try {
|
||||
|
||||
if (isPipelined()) {
|
||||
pipeline.zrevrangeByScoreWithScores(stringKey, minString, maxString);
|
||||
return null;
|
||||
}
|
||||
return RjcUtils.convertElementScore(session.zrevrangeByScoreWithScores(stringKey, minString, maxString));
|
||||
} catch (Exception ex) {
|
||||
throw convertRjcAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long zRank(byte[] key, byte[] value) {
|
||||
String stringKey = RjcUtils.decode(key);
|
||||
|
||||
@@ -17,11 +17,14 @@ package org.springframework.data.keyvalue.redis.core;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnection;
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.keyvalue.redis.core.ZSetOperations.TypedTuple;
|
||||
import org.springframework.data.keyvalue.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.keyvalue.redis.serializer.SerializationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -136,6 +139,15 @@ abstract class AbstractOperations<K, V> {
|
||||
return SerializationUtils.deserialize(rawValues, valueSerializer);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<TypedTuple<V>> deserializeTupleValues(Set<Tuple> rawValues) {
|
||||
Set<TypedTuple<V>> set = new LinkedHashSet<TypedTuple<V>>(rawValues.size());
|
||||
for (Tuple rawValue : rawValues) {
|
||||
set.add(new DefaultTypedTuple(valueSerializer.deserialize(rawValue.getValue()), rawValue.getScore()));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<V> deserializeValues(List<byte[]> rawValues) {
|
||||
return SerializationUtils.deserialize(rawValues, valueSerializer);
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.springframework.data.keyvalue.redis.core;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.core.ZSetOperations.TypedTuple;
|
||||
|
||||
|
||||
/**
|
||||
* ZSet (or SortedSet) operations bound to a certain key.
|
||||
@@ -39,6 +41,16 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
|
||||
|
||||
Set<V> reverseRange(long start, long end);
|
||||
|
||||
Set<V> reverseRangeByScore(double min, double max);
|
||||
|
||||
Set<TypedTuple<V>> rangeWithScores(long start, long end);
|
||||
|
||||
Set<TypedTuple<V>> rangeByScoreWithScores(double min, double max);
|
||||
|
||||
Set<TypedTuple<V>> reverseRangeWithScores(long start, long end);
|
||||
|
||||
Set<TypedTuple<V>> reverseRangeByScoreWithScores(double min, double max);
|
||||
|
||||
void removeRange(long start, long end);
|
||||
|
||||
void removeRangeByScore(double min, double max);
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.DataType;
|
||||
import org.springframework.data.keyvalue.redis.core.ZSetOperations.TypedTuple;
|
||||
|
||||
/**
|
||||
* Default implementation for {@link BoundZSetOperations}.
|
||||
@@ -76,6 +77,31 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
|
||||
return ops.rangeByScore(getKey(), min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TypedTuple<V>> rangeByScoreWithScores(double min, double max) {
|
||||
return ops.rangeByScoreWithScores(getKey(), min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TypedTuple<V>> rangeWithScores(long start, long end) {
|
||||
return ops.rangeWithScores(getKey(), start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<V> reverseRangeByScore(double min, double max) {
|
||||
return ops.reverseRangeByScore(getKey(), min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TypedTuple<V>> reverseRangeByScoreWithScores(double min, double max) {
|
||||
return ops.reverseRangeByScoreWithScores(getKey(), min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TypedTuple<V>> reverseRangeWithScores(long start, long end) {
|
||||
return ops.reverseRangeWithScores(getKey(), start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long rank(Object o) {
|
||||
return ops.rank(getKey(), o);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.redis.core;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.core.ZSetOperations.TypedTuple;
|
||||
|
||||
/**
|
||||
* Default implementation of TypedTuple.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class DefaultTypedTuple<V> implements TypedTuple<V> {
|
||||
|
||||
private final Double score;
|
||||
private final V value;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>DefaultTypedTuple</code> instance.
|
||||
*
|
||||
* @param value
|
||||
* @param score
|
||||
*/
|
||||
public DefaultTypedTuple(V value, Double score) {
|
||||
this.score = score;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnection;
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisZSetCommands.Tuple;
|
||||
|
||||
/**
|
||||
* Default implementation of {@link ZSetOperations}.
|
||||
@@ -76,7 +77,6 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
|
||||
}, true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Set<V> range(K key, final long start, final long end) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
@@ -91,7 +91,48 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
|
||||
return deserializeValues(rawValues);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Set<V> reverseRange(K key, final long start, final long end) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
|
||||
@Override
|
||||
public Set<byte[]> doInRedis(RedisConnection connection) {
|
||||
return connection.zRevRange(rawKey, start, end);
|
||||
}
|
||||
}, true);
|
||||
|
||||
return deserializeValues(rawValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TypedTuple<V>> rangeWithScores(K key, final long start, final long end) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {
|
||||
@Override
|
||||
public Set<Tuple> doInRedis(RedisConnection connection) {
|
||||
return connection.zRangeWithScores(rawKey, start, end);
|
||||
}
|
||||
}, true);
|
||||
|
||||
return deserializeTupleValues(rawValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TypedTuple<V>> reverseRangeWithScores(K key, final long start, final long end) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {
|
||||
@Override
|
||||
public Set<Tuple> doInRedis(RedisConnection connection) {
|
||||
return connection.zRevRangeWithScores(rawKey, start, end);
|
||||
}
|
||||
}, true);
|
||||
|
||||
return deserializeTupleValues(rawValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<V> rangeByScore(K key, final double min, final double max) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
@@ -106,6 +147,50 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
|
||||
return deserializeValues(rawValues);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<V> reverseRangeByScore(K key, final double min, final double max) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
|
||||
@Override
|
||||
public Set<byte[]> doInRedis(RedisConnection connection) {
|
||||
return connection.zRevRangeByScore(rawKey, min, max);
|
||||
}
|
||||
}, true);
|
||||
|
||||
return deserializeValues(rawValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TypedTuple<V>> rangeByScoreWithScores(K key, final double min, final double max) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {
|
||||
@Override
|
||||
public Set<Tuple> doInRedis(RedisConnection connection) {
|
||||
return connection.zRangeByScoreWithScores(rawKey, min, max);
|
||||
}
|
||||
}, true);
|
||||
|
||||
return deserializeTupleValues(rawValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TypedTuple<V>> reverseRangeByScoreWithScores(K key, final double min, final double max) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
Set<Tuple> rawValues = execute(new RedisCallback<Set<Tuple>>() {
|
||||
@Override
|
||||
public Set<Tuple> doInRedis(RedisConnection connection) {
|
||||
return connection.zRevRangeByScoreWithScores(rawKey, min, max);
|
||||
|
||||
}
|
||||
}, true);
|
||||
|
||||
return deserializeTupleValues(rawValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long rank(K key, Object o) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
@@ -171,21 +256,6 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
|
||||
}, true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Set<V> reverseRange(K key, final long start, final long end) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
|
||||
@Override
|
||||
public Set<byte[]> doInRedis(RedisConnection connection) {
|
||||
return connection.zRevRange(rawKey, start, end);
|
||||
}
|
||||
}, true);
|
||||
|
||||
return deserializeValues(rawValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double score(K key, Object o) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
@@ -26,6 +26,15 @@ import java.util.Set;
|
||||
*/
|
||||
public interface ZSetOperations<K, V> {
|
||||
|
||||
/**
|
||||
* Typed ZSet tuple.
|
||||
*/
|
||||
public interface TypedTuple<V> {
|
||||
V getValue();
|
||||
|
||||
Double getScore();
|
||||
}
|
||||
|
||||
void intersectAndStore(K key, K otherKey, K destKey);
|
||||
|
||||
void intersectAndStore(K key, Collection<K> otherKeys, K destKey);
|
||||
@@ -36,9 +45,19 @@ public interface ZSetOperations<K, V> {
|
||||
|
||||
Set<V> range(K key, long start, long end);
|
||||
|
||||
Set<V> reverseRange(K key, long start, long end);
|
||||
|
||||
Set<TypedTuple<V>> rangeWithScores(K key, long start, long end);
|
||||
|
||||
Set<TypedTuple<V>> reverseRangeWithScores(K key, long start, long end);
|
||||
|
||||
Set<V> rangeByScore(K key, double min, double max);
|
||||
|
||||
Set<V> reverseRange(K key, long start, long end);
|
||||
Set<V> reverseRangeByScore(K key, double min, double max);
|
||||
|
||||
Set<TypedTuple<V>> rangeByScoreWithScores(K key, double min, double max);
|
||||
|
||||
Set<TypedTuple<V>> reverseRangeByScoreWithScores(K key, double min, double max);
|
||||
|
||||
Boolean add(K key, V value, double score);
|
||||
|
||||
@@ -61,4 +80,4 @@ public interface ZSetOperations<K, V> {
|
||||
Long size(K key);
|
||||
|
||||
RedisOperations<K, V> getOperations();
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,7 @@ abstract class CollectionUtils {
|
||||
|
||||
static <K> Boolean renameIfAbsent(final K key, final K newKey, RedisOperations<K, ?> operations) {
|
||||
return operations.execute(new SessionCallback<Boolean>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Boolean execute(RedisOperations operations) throws DataAccessException {
|
||||
List<Object> exec = null;
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Set;
|
||||
import org.springframework.data.keyvalue.redis.connection.DataType;
|
||||
import org.springframework.data.keyvalue.redis.core.BoundZSetOperations;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisOperations;
|
||||
import org.springframework.data.keyvalue.redis.core.ZSetOperations.TypedTuple;
|
||||
|
||||
/**
|
||||
* Default implementation for {@link RedisZSet}.
|
||||
@@ -118,6 +119,31 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
|
||||
return boundZSetOps.rangeByScore(min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<E> reverseRangeByScore(double min, double max) {
|
||||
return boundZSetOps.reverseRangeByScore(min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TypedTuple<E>> rangeByScoreWithScores(double min, double max) {
|
||||
return boundZSetOps.rangeByScoreWithScores(min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TypedTuple<E>> rangeWithScores(long start, long end) {
|
||||
return boundZSetOps.rangeWithScores(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TypedTuple<E>> reverseRangeByScoreWithScores(double min, double max) {
|
||||
return boundZSetOps.reverseRangeByScoreWithScores(min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TypedTuple<E>> reverseRangeWithScores(long start, long end) {
|
||||
return boundZSetOps.reverseRangeWithScores(start, end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedisZSet<E> remove(long start, long end) {
|
||||
boundZSetOps.removeRange(start, end);
|
||||
|
||||
@@ -98,6 +98,7 @@ public class RedisCollectionFactoryBean implements InitializingBean, BeanNameAwa
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private RedisStore createStore(DataType dt) {
|
||||
switch (dt) {
|
||||
case LIST:
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.core.ZSetOperations.TypedTuple;
|
||||
|
||||
/**
|
||||
* Redis ZSet (or sorted set (by weight)). Acts as a {@link SortedSet} based on the given priorities or weights associated with each item.
|
||||
* <p/>
|
||||
@@ -44,6 +46,16 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
|
||||
|
||||
Set<E> rangeByScore(double min, double max);
|
||||
|
||||
Set<E> reverseRangeByScore(double min, double max);
|
||||
|
||||
Set<TypedTuple<E>> rangeWithScores(long start, long end);
|
||||
|
||||
Set<TypedTuple<E>> reverseRangeWithScores(long start, long end);
|
||||
|
||||
Set<TypedTuple<E>> rangeByScoreWithScores(double min, double max);
|
||||
|
||||
Set<TypedTuple<E>> reverseRangeByScoreWithScores(double min, double max);
|
||||
|
||||
RedisZSet<E> remove(long start, long end);
|
||||
|
||||
RedisZSet<E> removeByScore(double min, double max);
|
||||
|
||||
Reference in New Issue
Block a user