DATAREDIS-106 - Support for open interval for scores for sorted sets.
We now support open zset's interval for JedisConnection, JredisConnection, LettuceConnection, SrpConnection and DefaultStringRedisConnection. Original pull request: #97.
This commit is contained in:
committed by
Christoph Strobl
parent
5ca672d180
commit
cf46d6e766
@@ -2393,4 +2393,44 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
return delegate.getSentinelConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(String key, String min, String max) {
|
||||
Set<byte[]> results = delegate.zRangeByScore(serialize(key), min, max);
|
||||
if (isFutureConversion()) {
|
||||
addResultConverter(identityConverter);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(String key, String min, String max, long offset, long count) {
|
||||
Set<byte[]> results = delegate.zRangeByScore(serialize(key), min, max, offset, count);
|
||||
if (isFutureConversion()) {
|
||||
addResultConverter(identityConverter);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, String min, String max) {
|
||||
|
||||
Set<byte[]> results = delegate.zRangeByScore(key, min, max);
|
||||
if (isFutureConversion()) {
|
||||
addResultConverter(identityConverter);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, String min, String max, long offset, long count) {
|
||||
|
||||
Set<byte[]> results = delegate.zRangeByScore(key, min, max, offset, count);
|
||||
if (isFutureConversion()) {
|
||||
addResultConverter(identityConverter);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import org.springframework.data.redis.core.ScanOptions;
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Christoph Strobl
|
||||
* @author Thomas Darimont
|
||||
* @author David Liu
|
||||
*/
|
||||
public interface RedisZSetCommands {
|
||||
|
||||
@@ -346,4 +348,29 @@ public interface RedisZSetCommands {
|
||||
* @return
|
||||
*/
|
||||
Cursor<Tuple> zScan(byte[] key, ScanOptions options);
|
||||
|
||||
/**
|
||||
* Get elements where score is between {@code min} and {@code max} from sorted set.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see http://redis.io/commands/zrangebyscore
|
||||
* @param key
|
||||
* @param begin
|
||||
* @param end
|
||||
* @return
|
||||
*/
|
||||
Set<byte[]> zRangeByScore(byte[] key, String min, String max);
|
||||
|
||||
/**
|
||||
* Get elements in range from {@code begin} to {@code end} where score is between {@code min} and {@code max} from
|
||||
* sorted set.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see http://redis.io/commands/zrangebyscore
|
||||
* @param key
|
||||
* @param begin
|
||||
* @param end
|
||||
* @return
|
||||
*/
|
||||
Set<byte[]> zRangeByScore(byte[] key, String min, String max, long offset, long count);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@ import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Christoph Strobl
|
||||
* @author Thomas Darimont
|
||||
* @author David Liu
|
||||
*
|
||||
* @see RedisCallback
|
||||
* @see RedisSerializer
|
||||
* @see StringRedisTemplate
|
||||
@@ -345,4 +348,24 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
* @return
|
||||
*/
|
||||
Cursor<StringTuple> zScan(String key, ScanOptions options);
|
||||
|
||||
/**
|
||||
* @since 1.5
|
||||
* @param key
|
||||
* @param min
|
||||
* @param max
|
||||
* @return
|
||||
*/
|
||||
Set<byte[]> zRangeByScore(String key, String min, String max);
|
||||
|
||||
/**
|
||||
* @since 1.5
|
||||
* @param key
|
||||
* @param min
|
||||
* @param max
|
||||
* @param offset
|
||||
* @param count
|
||||
* @return
|
||||
*/
|
||||
Set<byte[]> zRangeByScore(String key, String min, String max, long offset, long count);
|
||||
}
|
||||
|
||||
@@ -3163,4 +3163,42 @@ public class JedisConnection extends AbstractRedisConnection {
|
||||
protected Jedis getJedis(RedisNode node) {
|
||||
return new Jedis(node.getHost(), node.getPort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, String min, String max) {
|
||||
|
||||
try {
|
||||
String keyStr = new String(key, "UTF-8");
|
||||
if (isPipelined()) {
|
||||
pipeline(new JedisResult(pipeline.zrangeByScore(keyStr, min, max)));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(new JedisResult(transaction.zrangeByScore(keyStr, min, max)));
|
||||
return null;
|
||||
}
|
||||
return JedisConverters.stringSetToByteSet().convert(jedis.zrangeByScore(keyStr, min, max));
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, String min, String max, long offset, long count) {
|
||||
|
||||
try {
|
||||
String keyStr = new String(key, "UTF-8");
|
||||
if (isPipelined()) {
|
||||
pipeline(new JedisResult(pipeline.zrangeByScore(keyStr, min, max, (int) offset, (int) count)));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(new JedisResult(transaction.zrangeByScore(keyStr, min, max, (int) offset, (int) count)));
|
||||
return null;
|
||||
}
|
||||
return JedisConverters.stringSetToByteSet().convert(jedis.zrangeByScore(keyStr, min, max, (int) offset, (int) count));
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1282,5 +1282,14 @@ public class JredisConnection extends AbstractRedisConnection {
|
||||
public Cursor<Entry<byte[], byte[]>> hScan(byte[] key, ScanOptions options) {
|
||||
throw new UnsupportedOperationException("'HSCAN' command is not uspported for jredis");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, String min, String max) {
|
||||
throw new UnsupportedOperationException("'zRangeByScore' command is not uspported for jredis");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, String min, String max, long offset, long count) {
|
||||
throw new UnsupportedOperationException("'zRangeByScore' command is not uspported for jredis");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3616,4 +3616,44 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, String min, String max) {
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(new LettuceResult(getAsyncConnection().zrangebyscore(key, min, max),
|
||||
LettuceConverters.bytesListToBytesSet()));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(new LettuceTxResult(getConnection().zrangebyscore(key, min, max),
|
||||
LettuceConverters.bytesListToBytesSet()));
|
||||
return null;
|
||||
}
|
||||
return LettuceConverters.toBytesSet(getConnection().zrangebyscore(key, min, max));
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, String min, String max, long offset, long count) {
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(new LettuceResult(getAsyncConnection().zrangebyscore(key, min, max, offset, count),
|
||||
LettuceConverters.bytesListToBytesSet()));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(new LettuceTxResult(getConnection().zrangebyscore(key, min, max, offset, count),
|
||||
LettuceConverters.bytesListToBytesSet()));
|
||||
return null;
|
||||
}
|
||||
return LettuceConverters.toBytesSet(getConnection().zrangebyscore(key, min, max, offset, count));
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2472,4 +2472,35 @@ public class SrpConnection extends AbstractRedisConnection {
|
||||
return arrays.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, String min, String max) {
|
||||
|
||||
try {
|
||||
String keyStr = new String(key, "UTF-8");
|
||||
if (isPipelined()) {
|
||||
pipeline(new SrpResult(pipeline.zrangebyscore(keyStr, min, max, null, EMPTY_PARAMS_ARRAY),
|
||||
SrpConverters.repliesToBytesSet()));
|
||||
return null;
|
||||
}
|
||||
return SrpConverters.toBytesSet(client.zrangebyscore(keyStr, min, max, null, EMPTY_PARAMS_ARRAY).data());
|
||||
} catch (Exception ex) {
|
||||
throw convertSrpAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<byte[]> zRangeByScore(byte[] key, String min, String max, long offset, long count) {
|
||||
|
||||
try {
|
||||
String keyStr = new String(key, "UTF-8");
|
||||
Object[] limit = limitParams(offset, count);
|
||||
if (isPipelined()) {
|
||||
pipeline(new SrpResult(pipeline.zrangebyscore(keyStr, min, max, null, limit), SrpConverters.repliesToBytesSet()));
|
||||
return null;
|
||||
}
|
||||
return SrpConverters.toBytesSet(client.zrangebyscore(keyStr, min, max, null, limit).data());
|
||||
} catch (Exception ex) {
|
||||
throw convertSrpAccessException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Christoph Strobl
|
||||
* @author Thomas Darimont
|
||||
* @author David Liu
|
||||
*/
|
||||
class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZSetOperations<K, V> {
|
||||
|
||||
@@ -392,4 +394,32 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Set<byte[]> rangeByScore(K key, final String min, final String max) {
|
||||
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
|
||||
|
||||
public Set<byte[]> doInRedis(RedisConnection connection) {
|
||||
return connection.zRangeByScore(rawKey, min, max);
|
||||
}
|
||||
}, true);
|
||||
|
||||
return rawValues;
|
||||
}
|
||||
|
||||
public Set<byte[]> rangeByScore(K key, final String min, final String max, final long offset, final long count) {
|
||||
|
||||
final byte[] rawKey = rawKey(key);
|
||||
|
||||
Set<byte[]> rawValues = execute(new RedisCallback<Set<byte[]>>() {
|
||||
|
||||
public Set<byte[]> doInRedis(RedisConnection connection) {
|
||||
return connection.zRangeByScore(rawKey, min, max, offset, count);
|
||||
}
|
||||
}, true);
|
||||
|
||||
return rawValues;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user