fix publish bug in RedisTemplate

This commit is contained in:
Costin Leau
2011-01-21 18:46:31 +02:00
parent 098155a69e
commit 0948b28b48
2 changed files with 37 additions and 7 deletions

View File

@@ -69,6 +69,8 @@ import org.springframework.util.ClassUtils;
*/
public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperations<K, V> {
private static final byte[] EMPTY_ARRAY = new byte[0];
private boolean exposeConnection = false;
private RedisSerializer keySerializer = new JdkSerializationRedisSerializer();
private RedisSerializer valueSerializer = new JdkSerializationRedisSerializer();
@@ -279,16 +281,16 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
@SuppressWarnings("unchecked")
private byte[] rawKey(Object key) {
return (key != null ? keySerializer.serialize(key) : null);
return (key != null ? keySerializer.serialize(key) : EMPTY_ARRAY);
}
private byte[] rawString(String key) {
return (key != null ? stringSerializer.serialize(key) : null);
return (key != null ? stringSerializer.serialize(key) : EMPTY_ARRAY);
}
@SuppressWarnings("unchecked")
private byte[] rawValue(Object value) {
return (value != null ? valueSerializer.serialize(value) : null);
return (value != null ? valueSerializer.serialize(value) : EMPTY_ARRAY);
}
private byte[][] rawKeys(Collection<K> keys) {
@@ -317,12 +319,12 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
@SuppressWarnings("unchecked")
private <HK> byte[] rawHashKey(HK value) {
return (value != null ? hashKeySerializer.serialize(value) : null);
return (value != null ? hashKeySerializer.serialize(value) : EMPTY_ARRAY);
}
@SuppressWarnings("unchecked")
private <HV> byte[] rawHashValue(HV value) {
return (value != null ? hashValueSerializer.serialize(value) : null);
return (value != null ? hashValueSerializer.serialize(value) : EMPTY_ARRAY);
}
@@ -390,7 +392,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
@SuppressWarnings("unchecked")
private String deserializeString(byte[] value) {
return (String) deserialize(value, stringSerializer);
return deserialize(value, stringSerializer);
}
@SuppressWarnings( { "unchecked" })
@@ -537,7 +539,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
execute(new RedisCallback<Object>() {
@Override
public Object doInRedis(RedisConnection connection) {
connection.publish(rawMessage, rawChannel);
connection.publish(rawChannel, rawMessage);
return null;
}
}, true);

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2011 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.data.keyvalue.redis.serializer;
/**
* Minimal class used for sharing pieces of code between the serializers
*
* @author Costin Leau
*/
abstract class SerializerUtils {
static boolean isEmpty(byte[] data) {
return (data == null || data.length == 0);
}
}