DATAKV-26
+ add String connection to RedisTemplate
This commit is contained in:
@@ -45,7 +45,6 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
|||||||
*/
|
*/
|
||||||
public DefaultStringRedisConnection(RedisConnection connection) {
|
public DefaultStringRedisConnection(RedisConnection connection) {
|
||||||
Assert.notNull(connection, "connection is required");
|
Assert.notNull(connection, "connection is required");
|
||||||
Assert.notNull(connection, "serializer is required");
|
|
||||||
this.delegate = connection;
|
this.delegate = connection;
|
||||||
this.serializer = new StringRedisSerializer();
|
this.serializer = new StringRedisSerializer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,13 +160,14 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
|||||||
RedisConnectionFactory factory = getConnectionFactory();
|
RedisConnectionFactory factory = getConnectionFactory();
|
||||||
RedisConnection conn = RedisConnectionUtils.getConnection(factory);
|
RedisConnection conn = RedisConnectionUtils.getConnection(factory);
|
||||||
|
|
||||||
|
boolean existingConnection = TransactionSynchronizationManager.hasResource(factory);
|
||||||
|
preProcessConnection(conn, existingConnection);
|
||||||
|
|
||||||
boolean pipelineStatus = conn.isPipelined();
|
boolean pipelineStatus = conn.isPipelined();
|
||||||
if (pipeline && !pipelineStatus) {
|
if (pipeline && !pipelineStatus) {
|
||||||
conn.openPipeline();
|
conn.openPipeline();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean existingConnection = TransactionSynchronizationManager.hasResource(factory);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
RedisConnection connToExpose = (exposeConnection ? conn : createRedisConnectionProxy(conn));
|
RedisConnection connToExpose = (exposeConnection ? conn : createRedisConnectionProxy(conn));
|
||||||
T result = action.doInRedis(connToExpose);
|
T result = action.doInRedis(connToExpose);
|
||||||
@@ -189,6 +190,15 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
|||||||
new CloseSuppressingInvocationHandler(pm));
|
new CloseSuppressingInvocationHandler(pm));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the connection (before any settings are executed on it). Default implementation returns the connection as is.
|
||||||
|
*
|
||||||
|
* @param connection redis connection
|
||||||
|
*/
|
||||||
|
protected RedisConnection preProcessConnection(RedisConnection connection, boolean existingConnection) {
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
protected <T> T postProcessResult(T result, RedisConnection conn, boolean existingConnection) {
|
protected <T> T postProcessResult(T result, RedisConnection conn, boolean existingConnection) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.keyvalue.redis.core;
|
package org.springframework.data.keyvalue.redis.core;
|
||||||
|
|
||||||
|
import org.springframework.data.keyvalue.redis.connection.DefaultStringRedisConnection;
|
||||||
|
import org.springframework.data.keyvalue.redis.connection.RedisConnection;
|
||||||
import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory;
|
import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.keyvalue.redis.connection.StringRedisConnection;
|
||||||
import org.springframework.data.keyvalue.redis.serializer.RedisSerializer;
|
import org.springframework.data.keyvalue.redis.serializer.RedisSerializer;
|
||||||
import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer;
|
import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
@@ -24,6 +27,9 @@ import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer;
|
|||||||
* this class provides a dedicated class that minimizes configuration of its more generic
|
* this class provides a dedicated class that minimizes configuration of its more generic
|
||||||
* {@link RedisTemplate template} especially in terms of serializers.
|
* {@link RedisTemplate template} especially in terms of serializers.
|
||||||
*
|
*
|
||||||
|
* <p/> Note that this template exposes the {@link RedisConnection} used by the {@link RedisCallback}
|
||||||
|
* as a {@link StringRedisConnection}.
|
||||||
|
*
|
||||||
* @author Costin Leau
|
* @author Costin Leau
|
||||||
*/
|
*/
|
||||||
public class StringRedisTemplate extends RedisTemplate<String, String> {
|
public class StringRedisTemplate extends RedisTemplate<String, String> {
|
||||||
@@ -52,4 +58,9 @@ public class StringRedisTemplate extends RedisTemplate<String, String> {
|
|||||||
setHashKeySerializer(stringSerializer);
|
setHashKeySerializer(stringSerializer);
|
||||||
setHashValueSerializer(stringSerializer);
|
setHashValueSerializer(stringSerializer);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
protected RedisConnection preProcessConnection(RedisConnection connection, boolean existingConnection) {
|
||||||
|
return new DefaultStringRedisConnection(connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user