Skip to content

Commit 69d42c8

Browse files
DATAREDIS-425 - Rebase on master and move mergeArrays to ByteUtils.
1 parent c9c1a05 commit 69d42c8

File tree

4 files changed

+63
-52
lines changed

4 files changed

+63
-52
lines changed

src/main/java/org/springframework/data/redis/connection/convert/Converters.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@
3535
import org.springframework.data.redis.connection.RedisClusterNode.SlotRange;
3636
import org.springframework.data.redis.connection.RedisNode.NodeType;
3737
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
38-
import org.springframework.util.Assert;
3938
import org.springframework.util.CollectionUtils;
4039
import org.springframework.util.NumberUtils;
4140
import org.springframework.util.StringUtils;
4241

4342
/**
4443
* Common type converters
45-
*
44+
*
4645
* @author Jennifer Hickey
4746
* @author Thomas Darimont
4847
* @author Mark Paluch
@@ -85,7 +84,7 @@ public RedisClusterNode convert(String source) {
8584
Set<Flag> flags = parseFlags(args);
8685

8786
String portPart = hostAndPort[1];
88-
if(portPart.contains("@")){
87+
if (portPart.contains("@")) {
8988
portPart = portPart.substring(0, portPart.indexOf('@'));
9089
}
9190

@@ -195,7 +194,7 @@ public static byte[] toBit(Boolean source) {
195194

196195
/**
197196
* Converts the result of a single line of {@code CLUSTER NODES} into a {@link RedisClusterNode}.
198-
*
197+
*
199198
* @param clusterNodesLine
200199
* @return
201200
* @since 1.7
@@ -206,7 +205,7 @@ protected static RedisClusterNode toClusterNode(String clusterNodesLine) {
206205

207206
/**
208207
* Converts lines from the result of {@code CLUSTER NODES} into {@link RedisClusterNode}s.
209-
*
208+
*
210209
* @param clusterNodes
211210
* @return
212211
* @since 1.7
@@ -228,6 +227,7 @@ public static Set<RedisClusterNode> toSetOfRedisClusterNodes(Collection<String>
228227

229228
/**
230229
* Converts the result of {@code CLUSTER NODES} into {@link RedisClusterNode}s.
230+
*
231231
* @param clusterNodes
232232
* @return
233233
* @since 1.7
@@ -259,24 +259,8 @@ public static List<Object> toObjects(Set<Tuple> tuples) {
259259
* @return
260260
*/
261261
public static Long toTimeMillis(String seconds, String microseconds) {
262-
return NumberUtils.parseNumber(seconds, Long.class) * 1000L + NumberUtils.parseNumber(microseconds, Long.class)
263-
/ 1000L;
262+
return NumberUtils.parseNumber(seconds, Long.class) * 1000L
263+
+ NumberUtils.parseNumber(microseconds, Long.class) / 1000L;
264264
}
265265

266-
/**
267-
* Merge multiple {@code byte} arrays into one array
268-
* @param firstArray must not be {@literal null}
269-
* @param additionalArrays must not be {@literal null}
270-
* @return
271-
*/
272-
public static byte[][] mergeArrays(byte[] firstArray, byte[]... additionalArrays){
273-
Assert.notNull(firstArray, "first array must not be null");
274-
Assert.notNull(additionalArrays, "additional arrays must not be null");
275-
276-
byte[][] result = new byte[additionalArrays.length + 1][];
277-
result[0] = firstArray;
278-
System.arraycopy(additionalArrays, 0, result, 1, additionalArrays.length);
279-
280-
return result;
281-
}
282266
}

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterConnection.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.springframework.data.redis.core.ScanOptions;
6666
import org.springframework.data.redis.core.types.Expiration;
6767
import org.springframework.data.redis.core.types.RedisClientInfo;
68+
import org.springframework.data.redis.util.ByteUtils;
6869
import org.springframework.util.Assert;
6970
import org.springframework.util.CollectionUtils;
7071
import org.springframework.util.ObjectUtils;
@@ -79,7 +80,7 @@
7980
* {@link RedisClusterConnection} implementation on top of {@link JedisCluster}.<br/>
8081
* Uses the native {@link JedisCluster} api where possible and falls back to direct node communication using
8182
* {@link Jedis} where needed.
82-
*
83+
*
8384
* @author Christoph Strobl
8485
* @author Mark Paluch
8586
* @since 1.7
@@ -126,7 +127,7 @@ public JedisClusterConnection(JedisCluster cluster) {
126127
/**
127128
* Create new {@link JedisClusterConnection} utilizing native connections via {@link JedisCluster} running commands
128129
* across the cluster via given {@link ClusterCommandExecutor}.
129-
*
130+
*
130131
* @param cluster must not be {@literal null}.
131132
* @param executor must not be {@literal null}.
132133
*/
@@ -894,7 +895,7 @@ public Long bitCount(byte[] key, long begin, long end) {
894895
@Override
895896
public Long bitOp(BitOperation op, byte[] destination, byte[]... keys) {
896897

897-
byte[][] allKeys = Converters.mergeArrays(destination, keys);
898+
byte[][] allKeys = ByteUtils.mergeArrays(destination, keys);
898899

899900
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
900901
try {
@@ -1332,7 +1333,7 @@ public Set<byte[]> doInCluster(Jedis client, byte[] key) {
13321333
@Override
13331334
public Long sInterStore(byte[] destKey, byte[]... keys) {
13341335

1335-
byte[][] allKeys = Converters.mergeArrays(destKey, keys);
1336+
byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys);
13361337

13371338
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
13381339
try {
@@ -1392,7 +1393,7 @@ public Set<byte[]> doInCluster(Jedis client, byte[] key) {
13921393
@Override
13931394
public Long sUnionStore(byte[] destKey, byte[]... keys) {
13941395

1395-
byte[][] allKeys = Converters.mergeArrays(destKey, keys);
1396+
byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys);
13961397

13971398
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
13981399
try {
@@ -1455,7 +1456,7 @@ public Set<byte[]> doInCluster(Jedis client, byte[] key) {
14551456
@Override
14561457
public Long sDiffStore(byte[] destKey, byte[]... keys) {
14571458

1458-
byte[][] allKeys = Converters.mergeArrays(destKey, keys);
1459+
byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys);
14591460

14601461
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
14611462
try {
@@ -2083,7 +2084,7 @@ public Long zRemRangeByScore(byte[] key, double min, double max) {
20832084
@Override
20842085
public Long zUnionStore(byte[] destKey, byte[]... sets) {
20852086

2086-
byte[][] allKeys = Converters.mergeArrays(destKey, sets);
2087+
byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets);
20872088

20882089
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
20892090

@@ -2104,7 +2105,7 @@ public Long zUnionStore(byte[] destKey, byte[]... sets) {
21042105
@Override
21052106
public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
21062107

2107-
byte[][] allKeys = Converters.mergeArrays(destKey, sets);
2108+
byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets);
21082109

21092110
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
21102111

@@ -2123,7 +2124,7 @@ public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte
21232124
@Override
21242125
public Long zInterStore(byte[] destKey, byte[]... sets) {
21252126

2126-
byte[][] allKeys = Converters.mergeArrays(destKey, sets);
2127+
byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets);
21272128

21282129
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
21292130

@@ -2140,7 +2141,7 @@ public Long zInterStore(byte[] destKey, byte[]... sets) {
21402141
@Override
21412142
public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
21422143

2143-
byte[][] allKeys = Converters.mergeArrays(destKey, sets);
2144+
byte[][] allKeys = ByteUtils.mergeArrays(destKey, sets);
21442145

21452146
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
21462147

@@ -3298,7 +3299,7 @@ public Long pfCount(byte[]... keys) {
32983299
@Override
32993300
public void pfMerge(byte[] destinationKey, byte[]... sourceKeys) {
33003301

3301-
byte[][] allKeys = Converters.mergeArrays(destinationKey, sourceKeys);
3302+
byte[][] allKeys = ByteUtils.mergeArrays(destinationKey, sourceKeys);
33023303

33033304
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
33043305
try {
@@ -3592,6 +3593,7 @@ public List<String> doInCluster(Jedis client) {
35923593
* (non-Javadoc)
35933594
* @see org.springframework.data.redis.connection.RedisClusterCommands#clusterGetMasterSlaveMap()
35943595
*/
3596+
@Override
35953597
public Map<RedisClusterNode, Collection<RedisClusterNode>> clusterGetMasterSlaveMap() {
35963598

35973599
List<NodeResult<Collection<RedisClusterNode>>> nodeResults = clusterCommandExecutor
@@ -3753,7 +3755,7 @@ public RedisSentinelConnection getSentinelConnection() {
37533755

37543756
/**
37553757
* {@link Jedis} specific {@link ClusterCommandCallback}.
3756-
*
3758+
*
37573759
* @author Christoph Strobl
37583760
* @param <T>
37593761
* @since 1.7
@@ -3771,7 +3773,7 @@ protected interface JedisMultiKeyClusterCommandCallback<T> extends MultiKeyClust
37713773

37723774
/**
37733775
* Jedis specific implementation of {@link ClusterNodeResourceProvider}.
3774-
*
3776+
*
37753777
* @author Christoph Strobl
37763778
* @since 1.7
37773779
*/
@@ -3781,7 +3783,7 @@ static class JedisClusterNodeResourceProvider implements ClusterNodeResourceProv
37813783

37823784
/**
37833785
* Creates new {@link JedisClusterNodeResourceProvider}.
3784-
*
3786+
*
37853787
* @param cluster must not be {@literal null}.
37863788
*/
37873789
public JedisClusterNodeResourceProvider(JedisCluster cluster) {
@@ -3829,20 +3831,20 @@ public void returnResourceForSpecificNode(RedisClusterNode node, Object client)
38293831

38303832
/**
38313833
* Jedis specific implementation of {@link ClusterTopologyProvider}.
3832-
*
3834+
*
38333835
* @author Christoph Strobl
38343836
* @since 1.7
38353837
*/
38363838
static class JedisClusterTopologyProvider implements ClusterTopologyProvider {
38373839

3838-
private Object lock = new Object();
3840+
private final Object lock = new Object();
38393841
private final JedisCluster cluster;
38403842
private long time = 0;
38413843
private ClusterTopology cached;
38423844

38433845
/**
38443846
* Create new {@link JedisClusterTopologyProvider}.s
3845-
*
3847+
*
38463848
* @param cluster
38473849
*/
38483850
public JedisClusterTopologyProvider(JedisCluster cluster) {

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnection.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.springframework.data.redis.core.Cursor;
5252
import org.springframework.data.redis.core.ScanOptions;
5353
import org.springframework.data.redis.core.types.RedisClientInfo;
54+
import org.springframework.data.redis.util.ByteUtils;
5455
import org.springframework.util.Assert;
5556
import org.springframework.util.CollectionUtils;
5657
import org.springframework.util.ObjectUtils;
@@ -102,7 +103,7 @@ public LettuceClusterConnection(RedisClusterClient clusterClient) {
102103
/**
103104
* Creates new {@link LettuceClusterConnection} using {@link RedisClusterClient} running commands across the cluster
104105
* via given {@link ClusterCommandExecutor}.
105-
*
106+
*
106107
* @param clusterClient must not be {@literal null}.
107108
* @param executor must not be {@literal null}.
108109
*/
@@ -131,6 +132,7 @@ public Cursor<byte[]> scan(long cursorId, ScanOptions options) {
131132
* (non-Javadoc)
132133
* @see org.springframework.data.redis.connection.lettuce.LettuceConnection#keys(byte[])
133134
*/
135+
@Override
134136
public Set<byte[]> keys(final byte[] pattern) {
135137

136138
Assert.notNull(pattern, "Pattern must not be null!");
@@ -156,6 +158,7 @@ public List<byte[]> doInCluster(RedisClusterConnection<byte[], byte[]> connectio
156158
* (non-Javadoc)
157159
* @see org.springframework.data.redis.connection.lettuce.LettuceConnection#flushAll()
158160
*/
161+
@Override
159162
public void flushAll() {
160163

161164
clusterCommandExecutor.executeCommandOnAllNodes(new LettuceClusterCommandCallback<String>() {
@@ -1109,7 +1112,7 @@ public Set<byte[]> doInCluster(RedisClusterConnection<byte[], byte[]> client, by
11091112
@Override
11101113
public Long sInterStore(byte[] destKey, byte[]... keys) {
11111114

1112-
byte[][] allKeys = Converters.mergeArrays(destKey, keys);
1115+
byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys);
11131116

11141117
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
11151118
return super.sInterStore(destKey, keys);
@@ -1161,7 +1164,7 @@ public Set<byte[]> doInCluster(RedisClusterConnection<byte[], byte[]> client, by
11611164
@Override
11621165
public Long sUnionStore(byte[] destKey, byte[]... keys) {
11631166

1164-
byte[][] allKeys = Converters.mergeArrays(destKey, keys);
1167+
byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys);
11651168

11661169
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
11671170
return super.sUnionStore(destKey, keys);
@@ -1216,7 +1219,7 @@ public Set<byte[]> doInCluster(RedisClusterConnection<byte[], byte[]> client, by
12161219
@Override
12171220
public Long sDiffStore(byte[] destKey, byte[]... keys) {
12181221

1219-
byte[][] allKeys = Converters.mergeArrays(destKey, keys);
1222+
byte[][] allKeys = ByteUtils.mergeArrays(destKey, keys);
12201223

12211224
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
12221225
return super.sDiffStore(destKey, keys);
@@ -1276,7 +1279,7 @@ public Long pfCount(byte[]... keys) {
12761279
@Override
12771280
public void pfMerge(byte[] destinationKey, byte[]... sourceKeys) {
12781281

1279-
byte[][] allKeys = Converters.mergeArrays(destinationKey, sourceKeys);
1282+
byte[][] allKeys = ByteUtils.mergeArrays(destinationKey, sourceKeys);
12801283

12811284
if (ClusterSlotHashUtil.isSameSlotForAllKeys(allKeys)) {
12821285
try {
@@ -1318,7 +1321,7 @@ public void multi() {
13181321
}
13191322

13201323
/*
1321-
*
1324+
*
13221325
* (non-Javadoc)
13231326
* @see org.springframework.data.redis.connection.lettuce.LettuceConnection#getConfig(java.lang.String)
13241327
*/
@@ -1538,7 +1541,7 @@ public Set<RedisClusterNode> doInCluster(RedisClusterConnection<byte[], byte[]>
15381541

15391542
/**
15401543
* Lettuce specific implementation of {@link ClusterCommandCallback}.
1541-
*
1544+
*
15421545
* @author Christoph Strobl
15431546
* @param <T>
15441547
* @since 1.7
@@ -1548,7 +1551,7 @@ protected interface LettuceClusterCommandCallback<T>
15481551

15491552
/**
15501553
* Lettuce specific implementation of {@link MultiKeyClusterCommandCallback}.
1551-
*
1554+
*
15521555
* @author Christoph Strobl
15531556
* @param <T>
15541557
* @since 1.7
@@ -1560,7 +1563,7 @@ protected interface LettuceMultiKeyClusterCommandCallback<T>
15601563

15611564
/**
15621565
* Lettuce specific implementation of {@link ClusterNodeResourceProvider}.
1563-
*
1566+
*
15641567
* @author Christoph Strobl
15651568
* @since 1.7
15661569
*/
@@ -1605,7 +1608,7 @@ public void returnResourceForSpecificNode(RedisClusterNode node, Object resource
16051608

16061609
/**
16071610
* Lettuce specific implementation of {@link ClusterTopologyProvider}.
1608-
*
1611+
*
16091612
* @author Christoph Strobl
16101613
* @since 1.7
16111614
*/

0 commit comments

Comments
 (0)