+ implement new Zset operations in jedis connection

This commit is contained in:
Costin Leau
2010-11-09 13:12:22 +02:00
parent a4f0e31c42
commit fcbd57a2c9
2 changed files with 76 additions and 1 deletions

View File

@@ -865,6 +865,19 @@ public class JedisConnection implements RedisConnection {
}
}
@Override
public Set<Tuple> 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<String> zRangeByScore(String key, double min, double max) {
try {
@@ -877,6 +890,55 @@ public class JedisConnection implements RedisConnection {
}
}
@Override
public Set<Tuple> 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<Tuple> 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<String> 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<Tuple> 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 {

View File

@@ -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<Tuple> convertJedisTuple(Set<redis.clients.jedis.Tuple> tuples) {
Set<Tuple> value = new LinkedHashSet<Tuple>(tuples.size());
for (redis.clients.jedis.Tuple tuple : tuples) {
value.add(new DefaultTuple(tuple.getElement(), tuple.getScore()));
}
return value;
}
}