+ moved some packages around
+ added some command support for JRedis
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.datastore.redis.core.connection;
|
||||
package org.springframework.datastore.redis.connection;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.datastore.redis.core.connection;
|
||||
package org.springframework.datastore.redis.connection;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.datastore.redis.core.connection;
|
||||
package org.springframework.datastore.redis.connection;
|
||||
|
||||
import org.springframework.datastore.redis.UncategorizedRedisException;
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.datastore.redis.core.connection;
|
||||
package org.springframework.datastore.redis.connection;
|
||||
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
|
||||
/**
|
||||
* Thread-safe factory of Redis connections. Additionally performs exception translation
|
||||
* between the underlying Redis client library and Spring DAO exceptions.
|
||||
* between the underlying Redis connection library and Spring DAO exceptions.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.datastore.redis.core.connection;
|
||||
package org.springframework.datastore.redis.connection;
|
||||
|
||||
/**
|
||||
* Hash-specific commands supported by Redis.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.datastore.redis.core.connection;
|
||||
package org.springframework.datastore.redis.connection;
|
||||
|
||||
/**
|
||||
* List-specific commands supported by Redis.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.datastore.redis.core.connection;
|
||||
package org.springframework.datastore.redis.connection;
|
||||
|
||||
/**
|
||||
* Set-specific commands supported by Redis.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.datastore.redis.core.connection;
|
||||
package org.springframework.datastore.redis.connection;
|
||||
|
||||
/**
|
||||
* String specific commands supported by Redis.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.datastore.redis.core.connection;
|
||||
package org.springframework.datastore.redis.connection;
|
||||
|
||||
/**
|
||||
* ZSet(SortedSet)-specific commands supported by Redis.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.datastore.redis.core.connection.jedis;
|
||||
package org.springframework.datastore.redis.connection.jedis;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -22,8 +22,8 @@ import java.util.Collection;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.datastore.keyvalue.UncategorizedKeyvalueStoreException;
|
||||
import org.springframework.datastore.redis.UncategorizedRedisException;
|
||||
import org.springframework.datastore.redis.core.connection.DataType;
|
||||
import org.springframework.datastore.redis.core.connection.RedisConnection;
|
||||
import org.springframework.datastore.redis.connection.DataType;
|
||||
import org.springframework.datastore.redis.connection.RedisConnection;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import redis.clients.jedis.Client;
|
||||
@@ -51,7 +51,7 @@ public class JedisConnection implements RedisConnection {
|
||||
|
||||
public JedisConnection(Jedis jedis) {
|
||||
this.jedis = jedis;
|
||||
// extract underlying client for batch operations
|
||||
// extract underlying connection for batch operations
|
||||
client = (Client) ReflectionUtils.getField(CLIENT_FIELD, jedis);
|
||||
transaction = new Transaction(client);
|
||||
}
|
||||
@@ -14,10 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.datastore.redis.core.connection.jedis;
|
||||
package org.springframework.datastore.redis.connection.jedis;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -25,8 +23,8 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.datastore.redis.core.connection.RedisConnection;
|
||||
import org.springframework.datastore.redis.core.connection.RedisConnectionFactory;
|
||||
import org.springframework.datastore.redis.connection.RedisConnection;
|
||||
import org.springframework.datastore.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -139,17 +137,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
|
||||
}
|
||||
|
||||
private static String getDefaultHostName() {
|
||||
String temp;
|
||||
try {
|
||||
InetAddress localMachine = InetAddress.getLocalHost();
|
||||
temp = localMachine.getHostName();
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Using hostname [" + temp + "] for hostname.");
|
||||
} catch (UnknownHostException e) {
|
||||
log.warn("Could not get host name, using 'localhost' as default value", e);
|
||||
temp = "localhost";
|
||||
}
|
||||
return temp;
|
||||
return "localhost";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.datastore.redis.core.connection.jedis;
|
||||
package org.springframework.datastore.redis.connection.jedis;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.datastore.redis.core.connection.jredis;
|
||||
package org.springframework.datastore.redis.connection.jredis;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -22,8 +22,8 @@ import org.jredis.RedisException;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.datastore.keyvalue.UncategorizedKeyvalueStoreException;
|
||||
import org.springframework.datastore.redis.UncategorizedRedisException;
|
||||
import org.springframework.datastore.redis.core.connection.DataType;
|
||||
import org.springframework.datastore.redis.core.connection.RedisConnection;
|
||||
import org.springframework.datastore.redis.connection.DataType;
|
||||
import org.springframework.datastore.redis.connection.RedisConnection;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
@@ -163,7 +163,12 @@ public class JredisConnection implements RedisConnection {
|
||||
|
||||
@Override
|
||||
public Integer lPush(String key, String value) {
|
||||
throw new UnsupportedOperationException();
|
||||
try {
|
||||
jredis.lpush(key, value);
|
||||
return null;
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -173,11 +178,19 @@ public class JredisConnection implements RedisConnection {
|
||||
|
||||
@Override
|
||||
public String get(String key) {
|
||||
throw new UnsupportedOperationException();
|
||||
try {
|
||||
return JredisUtils.convertToString(jredis.get(key), encoding);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(String key, String value) {
|
||||
throw new UnsupportedOperationException();
|
||||
try {
|
||||
jredis.set(key, value);
|
||||
} catch (RedisException ex) {
|
||||
throw JredisUtils.convertJredisAccessException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.datastore.redis.core.connection.jredis;
|
||||
package org.springframework.datastore.redis.connection.jredis;
|
||||
|
||||
import org.jredis.JRedis;
|
||||
import org.jredis.connector.ConnectionSpec;
|
||||
@@ -24,13 +24,13 @@ import org.jredis.ri.alphazero.connection.DefaultConnectionSpec;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.datastore.redis.core.connection.RedisConnection;
|
||||
import org.springframework.datastore.redis.core.connection.RedisConnectionFactory;
|
||||
import org.springframework.datastore.redis.connection.RedisConnection;
|
||||
import org.springframework.datastore.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Connection factory on top of {@link JRedis} client.
|
||||
* Connection factory on top of {@link JRedis} connection.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
@@ -14,10 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.datastore.redis.core.connection.jredis;
|
||||
package org.springframework.datastore.redis.connection.jredis;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.jredis.RedisException;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataRetrievalFailureException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
|
||||
/**
|
||||
@@ -30,4 +33,12 @@ public abstract class JredisUtils {
|
||||
public static DataAccessException convertJredisAccessException(RedisException ex) {
|
||||
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
public static String convertToString(byte[] bytes, String encoding) {
|
||||
try {
|
||||
return new String(bytes, encoding);
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw new DataRetrievalFailureException("Unsupported encoding " + encoding, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package org.springframework.datastore.redis.core;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.datastore.redis.core.connection.RedisConnectionFactory;
|
||||
import org.springframework.datastore.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.datastore.redis.core;
|
||||
|
||||
import org.springframework.datastore.redis.core.connection.RedisConnection;
|
||||
import org.springframework.datastore.redis.connection.RedisConnection;
|
||||
|
||||
/**
|
||||
* Callback interface for Redis code. To be used with {@link RedisTemplate} execution methods, often as anonymous
|
||||
|
||||
@@ -17,8 +17,8 @@ package org.springframework.datastore.redis.core;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.datastore.redis.core.connection.RedisConnection;
|
||||
import org.springframework.datastore.redis.core.connection.RedisConnectionFactory;
|
||||
import org.springframework.datastore.redis.connection.RedisConnection;
|
||||
import org.springframework.datastore.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.transaction.support.ResourceHolder;
|
||||
import org.springframework.transaction.support.ResourceHolderSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import org.springframework.datastore.redis.core.connection.RedisConnection;
|
||||
import org.springframework.datastore.redis.core.connection.RedisConnectionFactory;
|
||||
import org.springframework.datastore.redis.connection.RedisConnection;
|
||||
import org.springframework.datastore.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.datastore.redis.support.converter.RedisConverter;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -29,7 +29,7 @@ import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* Helper class that simplifies Redis data access code. Automatically converts Redis client exceptions into
|
||||
* Helper class that simplifies Redis data access code. Automatically converts Redis connection exceptions into
|
||||
* DataAccessExceptions, following the org.springframework.dao exception hierarchy.
|
||||
*
|
||||
* The central method is execute, supporting Redis access code implementing the {@link RedisCallback} interface.
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.datastore.redis.support;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
|
||||
/**
|
||||
* Interface implemented by Spring integrations with Redis for drivers
|
||||
* that throw runtime and checked exceptions.
|
||||
*
|
||||
* @author Mark Pollack
|
||||
*
|
||||
*/
|
||||
public interface RedisPersistenceExceptionTranslator {
|
||||
|
||||
//NOTE some client libraries throw checked exceptions.
|
||||
DataAccessException translateException(Exception ex);
|
||||
}
|
||||
Reference in New Issue
Block a user