diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index d58ab847d..8b083554b 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -69,6 +69,8 @@ import org.springframework.util.ClassUtils; */ public class RedisTemplate extends RedisAccessor implements RedisOperations { + 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 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 keys) { @@ -317,12 +319,12 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation @SuppressWarnings("unchecked") private byte[] rawHashKey(HK value) { - return (value != null ? hashKeySerializer.serialize(value) : null); + return (value != null ? hashKeySerializer.serialize(value) : EMPTY_ARRAY); } @SuppressWarnings("unchecked") private 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 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 extends RedisAccessor implements RedisOperation execute(new RedisCallback() { @Override public Object doInRedis(RedisConnection connection) { - connection.publish(rawMessage, rawChannel); + connection.publish(rawChannel, rawMessage); return null; } }, true); diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/SerializerUtils.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/SerializerUtils.java new file mode 100644 index 000000000..d78954b9e --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/serializer/SerializerUtils.java @@ -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); + } +}