+ adjust return type for rename

+ replace most of the existing UOE with actual work in JRedis connection
This commit is contained in:
Costin Leau
2010-11-09 13:27:20 +02:00
parent 03d4a4f770
commit 6e98ecb1e9
4 changed files with 91 additions and 23 deletions

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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<String> 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();
}
}

View File

@@ -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;
}
}