diff --git a/src/main/java/org/springframework/data/redis/connection/sredis/SRedisConnection.java b/src/main/java/org/springframework/data/redis/connection/sredis/SRedisConnection.java index aa07fb1bd..dace9c2ce 100644 --- a/src/main/java/org/springframework/data/redis/connection/sredis/SRedisConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/sredis/SRedisConnection.java @@ -107,7 +107,6 @@ public class SRedisConnection implements RedisConnection { } } - @SuppressWarnings("unchecked") public List closePipeline() { if (pipeline != null) { ListenableFuture reply = pipeline.exec(); @@ -130,10 +129,10 @@ public class SRedisConnection implements RedisConnection { try { if (isPipelined()) { - pipeline.sort(key, sort, null, null); + pipeline.sort(key, sort, null, (Object[]) null); return null; } - return SRedisUtils.toBytesList(client.sort(key, sort, null, null).byteArrays); + return SRedisUtils.toBytesList(client.sort(key, sort, null, (Object[]) null).byteArrays); } catch (Exception ex) { throw convertSRAccessException(ex); } @@ -145,10 +144,10 @@ public class SRedisConnection implements RedisConnection { try { if (isPipelined()) { - pipeline.sort(key, sort, null, null); + pipeline.sort(key, sort, null, (Object[]) null); return null; } - return SRedisUtils.toLong(client.sort(key, sort, null, null).byteArrays); + return SRedisUtils.toLong(client.sort(key, sort, null, (Object[]) null).byteArrays); } catch (Exception ex) { throw convertSRAccessException(ex); } @@ -340,10 +339,10 @@ public class SRedisConnection implements RedisConnection { public Long del(byte[]... keys) { try { if (isPipelined()) { - pipeline.del(keys); + pipeline.del((Object[]) keys); return null; } - return client.del(keys).integer; + return client.del((Object[]) keys).integer; } catch (Exception ex) { throw convertSRAccessException(ex); } @@ -640,10 +639,10 @@ public class SRedisConnection implements RedisConnection { public List mGet(byte[]... keys) { try { if (isPipelined()) { - pipeline.mget(keys); + pipeline.mget((Object[]) keys); return null; } - return SRedisUtils.toBytesList(client.mget(keys).byteArrays); + return SRedisUtils.toBytesList(client.mget((Object) keys).byteArrays); } catch (Exception ex) { throw convertSRAccessException(ex); } @@ -653,10 +652,10 @@ public class SRedisConnection implements RedisConnection { public void mSet(Map tuples) { try { if (isPipelined()) { - pipeline.mset(SRedisUtils.convert(tuples)); + pipeline.mset((Object[]) SRedisUtils.convert(tuples)); return; } - client.mset(SRedisUtils.convert(tuples)); + client.mset((Object[]) SRedisUtils.convert(tuples)); } catch (Exception ex) { throw convertSRAccessException(ex); } @@ -666,10 +665,10 @@ public class SRedisConnection implements RedisConnection { public void mSetNX(Map tuples) { try { if (isPipelined()) { - pipeline.msetnx(SRedisUtils.convert(tuples)); + pipeline.msetnx((Object[]) SRedisUtils.convert(tuples)); return; } - client.msetnx(SRedisUtils.convert(tuples)); + client.msetnx((Object[]) SRedisUtils.convert(tuples)); } catch (Exception ex) { throw convertSRAccessException(ex); } @@ -1084,10 +1083,10 @@ public class SRedisConnection implements RedisConnection { public Set sDiff(byte[]... keys) { try { if (isPipelined()) { - pipeline.sdiff(keys); + pipeline.sdiff((Object[]) keys); return null; } - return SRedisUtils.toSet(client.sdiff(keys).byteArrays); + return SRedisUtils.toSet(client.sdiff((Object[]) keys).byteArrays); } catch (Exception ex) { throw convertSRAccessException(ex); } @@ -1097,10 +1096,10 @@ public class SRedisConnection implements RedisConnection { public void sDiffStore(byte[] destKey, byte[]... keys) { try { if (isPipelined()) { - pipeline.sdiffstore(destKey, keys); + pipeline.sdiffstore(destKey, (Object[]) keys); return; } - client.sdiffstore(destKey, keys); + client.sdiffstore(destKey, (Object[]) keys); } catch (Exception ex) { throw convertSRAccessException(ex); } @@ -1110,10 +1109,10 @@ public class SRedisConnection implements RedisConnection { public Set sInter(byte[]... keys) { try { if (isPipelined()) { - pipeline.sinter(keys); + pipeline.sinter((Object[]) keys); return null; } - return SRedisUtils.toSet(client.sinter(keys).byteArrays); + return SRedisUtils.toSet(client.sinter((Object[]) keys).byteArrays); } catch (Exception ex) { throw convertSRAccessException(ex); } @@ -1123,10 +1122,10 @@ public class SRedisConnection implements RedisConnection { public void sInterStore(byte[] destKey, byte[]... keys) { try { if (isPipelined()) { - pipeline.sinterstore(destKey, keys); + pipeline.sinterstore(destKey, (Object[]) keys); return; } - client.sinterstore(destKey, keys); + client.sinterstore(destKey, (Object[]) keys); } catch (Exception ex) { throw convertSRAccessException(ex); } @@ -1214,10 +1213,10 @@ public class SRedisConnection implements RedisConnection { public Set sUnion(byte[]... keys) { try { if (isPipelined()) { - pipeline.sunion(keys); + pipeline.sunion((Object[]) keys); return null; } - return SRedisUtils.toSet(client.sunion(keys).byteArrays); + return SRedisUtils.toSet(client.sunion((Object[]) keys).byteArrays); } catch (Exception ex) { throw convertSRAccessException(ex); } @@ -1227,10 +1226,10 @@ public class SRedisConnection implements RedisConnection { public void sUnionStore(byte[] destKey, byte[]... keys) { try { if (isPipelined()) { - pipeline.sunionstore(destKey, keys); + pipeline.sunionstore(destKey, (Object[]) keys); return; } - client.sunionstore(destKey, keys); + client.sunionstore(destKey, (Object[]) keys); } catch (Exception ex) { throw convertSRAccessException(ex); } @@ -1687,10 +1686,10 @@ public class SRedisConnection implements RedisConnection { public List hMGet(byte[] key, byte[]... fields) { try { if (isPipelined()) { - pipeline.hmget(key, fields); + pipeline.hmget(key, (Object[]) fields); return null; } - return SRedisUtils.toBytesList(client.hmget(key, fields).byteArrays); + return SRedisUtils.toBytesList(client.hmget(key, (Object[]) fields).byteArrays); } catch (Exception ex) { throw convertSRAccessException(ex); } diff --git a/src/main/java/org/springframework/data/redis/connection/sredis/SRedisSubscription.java b/src/main/java/org/springframework/data/redis/connection/sredis/SRedisSubscription.java index 06a2db247..fd7ce5977 100644 --- a/src/main/java/org/springframework/data/redis/connection/sredis/SRedisSubscription.java +++ b/src/main/java/org/springframework/data/redis/connection/sredis/SRedisSubscription.java @@ -36,36 +36,36 @@ class SRedisSubscription extends AbstractSubscription { } protected void doClose() { - client.unsubscribe(null); - client.punsubscribe(null); + client.unsubscribe((Object[]) null); + client.punsubscribe((Object[]) null); } protected void doPsubscribe(byte[]... patterns) { - client.psubscribe(patterns); + client.psubscribe((Object[]) patterns); } protected void doPUnsubscribe(boolean all, byte[]... patterns) { if (all) { - client.punsubscribe(null); + client.punsubscribe((Object[]) null); } else { - client.punsubscribe(patterns); + client.punsubscribe((Object[]) patterns); } } protected void doSubscribe(byte[]... channels) { - client.subscribe(channels); + client.subscribe((Object[]) channels); } protected void doUnsubscribe(boolean all, byte[]... channels) { if (all) { - client.unsubscribe(null); + client.unsubscribe((Object[]) null); } else { - client.unsubscribe(channels); + client.unsubscribe((Object[]) channels); } } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/redis/connection/sredis/SRedisUtils.java b/src/main/java/org/springframework/data/redis/connection/sredis/SRedisUtils.java index 1a95852fb..5019a7a89 100644 --- a/src/main/java/org/springframework/data/redis/connection/sredis/SRedisUtils.java +++ b/src/main/java/org/springframework/data/redis/connection/sredis/SRedisUtils.java @@ -19,6 +19,7 @@ package org.springframework.data.redis.connection.sredis; import java.io.StringReader; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -82,6 +83,10 @@ abstract class SRedisUtils { static List toBytesList(Object[] byteArrays) { List list = new ArrayList(byteArrays.length); + if (byteArrays.length == 1 && byteArrays[0] == null) { + return Collections.emptyList(); + } + for (Object obj : byteArrays) { if (obj instanceof byte[]) list.add((byte[]) obj); diff --git a/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionIntegrationTests.java new file mode 100644 index 000000000..0bf3a8414 --- /dev/null +++ b/src/test/java/org/springframework/data/redis/connection/srp/SrpConnectionIntegrationTests.java @@ -0,0 +1,55 @@ +/* + * Copyright 2011-2012 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.redis.connection.srp; + +import org.junit.Test; +import org.springframework.data.redis.SettingsUtils; +import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.sredis.SRedisConnectionFactory; + +import redis.client.RedisClient; + +/** + * @author Costin Leau + */ +public class SrpConnectionIntegrationTests extends AbstractConnectionIntegrationTests { + SRedisConnectionFactory factory; + + public SrpConnectionIntegrationTests() { + factory = new SRedisConnectionFactory(); + factory.setPort(SettingsUtils.getPort()); + factory.setHostName(SettingsUtils.getHost()); + + factory.afterPropertiesSet(); + } + + + protected RedisConnectionFactory getConnectionFactory() { + return factory; + } + + @Test + public void testRaw() throws Exception { + RedisClient rc = (RedisClient) factory.getConnection().getNativeConnection(); + + System.out.println(rc.dbsize()); + System.out.println(rc.exists("foobar")); + rc.set("foobar", "barfoo"); + System.out.println(rc.get("foobar")); + } +} diff --git a/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java b/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java index 0108cda85..c35cc0e55 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java +++ b/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java @@ -23,6 +23,7 @@ import org.springframework.data.redis.SettingsUtils; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.redis.connection.jredis.JredisConnectionFactory; import org.springframework.data.redis.connection.rjc.RjcConnectionFactory; +import org.springframework.data.redis.connection.sredis.SRedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.serializer.JacksonJsonRedisSerializer; @@ -135,6 +136,32 @@ public abstract class CollectionTestParams { jsonPersonTemplateRJC.setConnectionFactory(rjcConnFactory); jsonPersonTemplateRJC.afterPropertiesSet(); + // SRP + SRedisConnectionFactory srConnFactory = new SRedisConnectionFactory(); + srConnFactory.setPort(SettingsUtils.getPort()); + srConnFactory.setHostName(SettingsUtils.getHost()); + srConnFactory.afterPropertiesSet(); + + RedisTemplate stringTemplateSRP = new StringRedisTemplate(srConnFactory); + RedisTemplate personTemplateSRP = new RedisTemplate(); + personTemplateSRP.setConnectionFactory(srConnFactory); + personTemplateSRP.afterPropertiesSet(); + + RedisTemplate xstreamStringTemplateSRP = new RedisTemplate(); + xstreamStringTemplateSRP.setConnectionFactory(srConnFactory); + xstreamStringTemplateSRP.setDefaultSerializer(serializer); + xstreamStringTemplateSRP.afterPropertiesSet(); + + RedisTemplate xstreamPersonTemplateSRP = new RedisTemplate(); + xstreamPersonTemplateSRP.setValueSerializer(serializer); + xstreamPersonTemplateSRP.setConnectionFactory(srConnFactory); + xstreamPersonTemplateSRP.afterPropertiesSet(); + + RedisTemplate jsonPersonTemplateSRP = new RedisTemplate(); + jsonPersonTemplateSRP.setValueSerializer(jsonSerializer); + jsonPersonTemplateSRP.setConnectionFactory(srConnFactory); + jsonPersonTemplateSRP.afterPropertiesSet(); + return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { stringFactory, stringTemplateRJC }, { personFactory, personTemplateRJC }, //{ stringFactory, stringTemplateJR }, @@ -146,6 +173,10 @@ public abstract class CollectionTestParams { { personFactory, jsonPersonTemplate }, //{ personFactory, jsonPersonTemplateJR }, { stringFactory, xstreamStringTemplateRJC }, { personFactory, xstreamPersonTemplateRJC }, - { personFactory, jsonPersonTemplateRJC } }); + { personFactory, jsonPersonTemplateRJC }, + { stringFactory, stringTemplateSRP },{ personFactory, personTemplateSRP }, + { stringFactory, xstreamStringTemplateSRP }, { personFactory, xstreamPersonTemplateSRP }, + { personFactory, jsonPersonTemplateSRP } + }); } }