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);
|
||||
|
||||
Reference in New Issue
Block a user