fix casting problems with varargs
add integration tests
This commit is contained in:
@@ -107,7 +107,6 @@ public class SRedisConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Object> closePipeline() {
|
||||
if (pipeline != null) {
|
||||
ListenableFuture<MultiBulkReply> 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<byte[]> 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<byte[], byte[]> 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<byte[], byte[]> 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<byte[]> 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<byte[]> 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<byte[]> 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<byte[]> 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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<byte[]> toBytesList(Object[] byteArrays) {
|
||||
List<byte[]> list = new ArrayList<byte[]>(byteArrays.length);
|
||||
if (byteArrays.length == 1 && byteArrays[0] == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
for (Object obj : byteArrays) {
|
||||
if (obj instanceof byte[])
|
||||
list.add((byte[]) obj);
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
@@ -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<String, String> stringTemplateSRP = new StringRedisTemplate(srConnFactory);
|
||||
RedisTemplate<String, Person> personTemplateSRP = new RedisTemplate<String, Person>();
|
||||
personTemplateSRP.setConnectionFactory(srConnFactory);
|
||||
personTemplateSRP.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> xstreamStringTemplateSRP = new RedisTemplate<String, Person>();
|
||||
xstreamStringTemplateSRP.setConnectionFactory(srConnFactory);
|
||||
xstreamStringTemplateSRP.setDefaultSerializer(serializer);
|
||||
xstreamStringTemplateSRP.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> xstreamPersonTemplateSRP = new RedisTemplate<String, Person>();
|
||||
xstreamPersonTemplateSRP.setValueSerializer(serializer);
|
||||
xstreamPersonTemplateSRP.setConnectionFactory(srConnFactory);
|
||||
xstreamPersonTemplateSRP.afterPropertiesSet();
|
||||
|
||||
RedisTemplate<String, Person> jsonPersonTemplateSRP = new RedisTemplate<String, Person>();
|
||||
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 }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user