diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnection.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnection.java index 74e44454d..d7a09ab0c 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnection.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisConnection.java @@ -865,6 +865,19 @@ public class JedisConnection implements RedisConnection { } } + @Override + public Set zRangeWithScore(String key, int start, int end) { + try { + if (isQueueing()) { + transaction.zrangeWithScores(key, start, end); + return null; + } + return JedisUtils.convertJedisTuple(jedis.zrangeWithScores(key, start, end)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + @Override public Set zRangeByScore(String key, double min, double max) { try { @@ -877,6 +890,55 @@ public class JedisConnection implements RedisConnection { } } + @Override + public Set zRangeByScoreWithScore(String key, double min, double max) { + try { + if (isQueueing()) { + throw new UnsupportedOperationException(); + } + return JedisUtils.convertJedisTuple(jedis.zrangeByScoreWithScores(key, min, max)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public Set zRevRangeWithScore(String key, int start, int end) { + try { + if (isQueueing()) { + transaction.zrangeWithScores(key, start, end); + return null; + } + return JedisUtils.convertJedisTuple(jedis.zrangeByScoreWithScores(key, start, end)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public Set zRangeByScore(String key, double min, double max, int offset, int count) { + try { + if (isQueueing()) { + throw new UnsupportedOperationException(); + } + return jedis.zrangeByScore(key, min, max, offset, count); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + + @Override + public Set zRangeByScoreWithScore(String key, double min, double max, int offset, int count) { + try { + if (isQueueing()) { + throw new UnsupportedOperationException(); + } + return JedisUtils.convertJedisTuple(jedis.zrangeByScoreWithScores(key, min, max, offset, count)); + } catch (Exception ex) { + throw convertJedisAccessException(ex); + } + } + @Override public Integer zRank(String key, String value) { try { diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisUtils.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisUtils.java index d09769bfc..670a8d4a7 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisUtils.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jedis/JedisUtils.java @@ -18,12 +18,16 @@ package org.springframework.datastore.redis.connection.jedis; import java.io.IOException; import java.net.UnknownHostException; +import java.util.LinkedHashSet; +import java.util.Set; import java.util.concurrent.TimeoutException; import org.springframework.dao.DataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.datastore.redis.RedisConnectionFailureException; import org.springframework.datastore.redis.UncategorizedRedisException; +import org.springframework.datastore.redis.connection.DefaultTuple; +import org.springframework.datastore.redis.connection.RedisZSetCommands.Tuple; import redis.clients.jedis.JedisException; @@ -67,4 +71,13 @@ public abstract class JedisUtils { static Boolean convertCodeReply(Integer code) { return (code != null ? code == 1 : null); } -} + + static Set convertJedisTuple(Set tuples) { + Set value = new LinkedHashSet(tuples.size()); + for (redis.clients.jedis.Tuple tuple : tuples) { + value.add(new DefaultTuple(tuple.getElement(), tuple.getScore())); + } + + return value; + } +} \ No newline at end of file