diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisCommands.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisCommands.java index fb4d98ca0..a31e04b2c 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisCommands.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/RedisCommands.java @@ -35,8 +35,7 @@ public interface RedisCommands extends RedisTxCommands, RedisStringCommands, Red String randomKey(); - //TODO see whether the status code can be properly intercepted - Boolean rename(String oldName, String newName); + void rename(String oldName, String newName); Boolean renameNx(String oldName, String newName); 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 d7a09ab0c..72a2d9827 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 @@ -227,13 +227,12 @@ public class JedisConnection implements RedisConnection { } @Override - public Boolean rename(String oldName, String newName) { + public void rename(String oldName, String newName) { try { if (isQueueing()) { transaction.rename(oldName, newName); - return null; } - return (JedisUtils.isStatusOk(jedis.rename(oldName, newName))); + jedis.rename(oldName, newName); } catch (Exception ex) { throw convertJedisAccessException(ex); } diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisConnection.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisConnection.java index 0ab848354..11c330d44 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisConnection.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisConnection.java @@ -76,17 +76,29 @@ public class JredisConnection implements RedisConnection { @Override public Integer dbSize() { - throw new UnsupportedOperationException(); + try { + return Integer.valueOf((int) jredis.dbsize()); + } catch (RedisException ex) { + throw JredisUtils.convertJredisAccessException(ex); + } } @Override public Integer del(String... keys) { - throw new UnsupportedOperationException(); + try { + return Integer.valueOf((int) jredis.del(keys)); + } catch (RedisException ex) { + throw JredisUtils.convertJredisAccessException(ex); + } } @Override public void discard() { - throw new UnsupportedOperationException(); + try { + jredis.discard(); + } catch (RedisException ex) { + throw JredisUtils.convertJredisAccessException(ex); + } } @Override @@ -96,17 +108,29 @@ public class JredisConnection implements RedisConnection { @Override public Boolean exists(String key) { - throw new UnsupportedOperationException(); + try { + return jredis.exists(key); + } catch (RedisException ex) { + throw JredisUtils.convertJredisAccessException(ex); + } } @Override public Boolean expire(String key, int seconds) { - throw new UnsupportedOperationException(); + try { + return jredis.expire(key, seconds); + } catch (RedisException ex) { + throw JredisUtils.convertJredisAccessException(ex); + } } @Override public Collection keys(String pattern) { - throw new UnsupportedOperationException(); + try { + return jredis.keys(pattern); + } catch (RedisException ex) { + throw JredisUtils.convertJredisAccessException(ex); + } } @Override @@ -121,17 +145,29 @@ public class JredisConnection implements RedisConnection { @Override public String randomKey() { - throw new UnsupportedOperationException(); + try { + return jredis.randomkey(); + } catch (RedisException ex) { + throw JredisUtils.convertJredisAccessException(ex); + } } @Override - public Boolean rename(String oldName, String newName) { - throw new UnsupportedOperationException(); + public void rename(String oldName, String newName) { + try { + jredis.rename(oldName, newName); + } catch (RedisException ex) { + throw JredisUtils.convertJredisAccessException(ex); + } } @Override public Boolean renameNx(String oldName, String newName) { - throw new UnsupportedOperationException(); + try { + return jredis.renamenx(oldName, newName); + } catch (RedisException ex) { + throw JredisUtils.convertJredisAccessException(ex); + } } @Override @@ -141,12 +177,20 @@ public class JredisConnection implements RedisConnection { @Override public Integer ttl(String key) { - throw new UnsupportedOperationException(); + try { + return Integer.valueOf((int) jredis.ttl(key)); + } catch (RedisException ex) { + throw JredisUtils.convertJredisAccessException(ex); + } } @Override public DataType type(String key) { - throw new UnsupportedOperationException(); + try { + return JredisUtils.convertDataType(jredis.type(key)); + } catch (RedisException ex) { + throw JredisUtils.convertJredisAccessException(ex); + } } @Override @@ -159,11 +203,6 @@ public class JredisConnection implements RedisConnection { throw new UnsupportedOperationException(); } - @Override - public Integer hSet(String key, String field, String value) { - throw new UnsupportedOperationException(); - } - @Override public String get(String key) { try { @@ -664,4 +703,14 @@ public class JredisConnection implements RedisConnection { public Integer zUnionStore(String destKey, String... sets) { throw new UnsupportedOperationException(); } + + + // + // Hash commands + // + + @Override + public Integer hSet(String key, String field, String value) { + throw new UnsupportedOperationException(); + } } \ No newline at end of file diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisUtils.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisUtils.java index 80d72e696..d8a9c209f 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisUtils.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/connection/jredis/JredisUtils.java @@ -23,9 +23,11 @@ import java.util.LinkedHashSet; import java.util.List; import org.jredis.RedisException; +import org.jredis.RedisType; import org.springframework.dao.DataAccessException; import org.springframework.dao.DataRetrievalFailureException; import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.datastore.redis.connection.DataType; /** * Helper class featuring methods for JRedis connection handling, providing support for exception translation. @@ -60,4 +62,23 @@ public abstract class JredisUtils { throw new DataRetrievalFailureException("Unsupported encoding " + encoding, ex); } } -} + + static DataType convertDataType(RedisType type) { + switch (type) { + case NONE: + return DataType.NONE; + case string: + return DataType.STRING; + case list: + return DataType.LIST; + case set: + return DataType.SET; + //case zset: + // return DataType.ZSET; + case hash: + return DataType.HASH; + } + + return null; + } +} \ No newline at end of file