Skip to content

Commit aa3c407

Browse files
committed
DATAREDIS-528 - Polishing.
Extend date ranges in license headers. Add author tags. Update documentation. Original pull request: spring-projects#222.
1 parent 4be4ed0 commit aa3c407

12 files changed

+102
-28
lines changed

src/main/asciidoc/new-features.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ New and noteworthy in the latest releases.
88

99
* Support for Redis http://redis.io/commands#geo[GEO] commands.
1010
* Support for Geospatial Indexes using Spring Data Repository abstractions (see <<redis.repositories.indexes.geospatial>>).
11+
* Upgrade to `Lettuce` 4.2. Lettuce 4.2 requires Java 8.
1112

1213
[[new-in-1.7.0]]
1314
== New in Spring Data Redis 1.7

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2015 the original author or authors.
2+
* Copyright 2013-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,16 +41,28 @@ public AuthenticatingRedisClient(String host, String password) {
4141
super(null, RedisURI.builder().withHost(host).withPassword(password).build());
4242
}
4343

44+
/*
45+
* (non-Javadoc)
46+
* @see com.lambdaworks.redis.RedisClient#connect(com.lambdaworks.redis.codec.RedisCodec)
47+
*/
4448
@Override
4549
public <K, V> StatefulRedisConnection<K, V> connect(RedisCodec<K, V> codec) {
4650
return super.connect(codec);
4751
}
4852

53+
/*
54+
* (non-Javadoc)
55+
* @see com.lambdaworks.redis.RedisClient#connectAsync(com.lambdaworks.redis.codec.RedisCodec)
56+
*/
4957
@Override
5058
public <K, V> RedisAsyncCommands<K, V> connectAsync(RedisCodec<K, V> codec) {
5159
return super.connectAsync(codec);
5260
}
5361

62+
/*
63+
* (non-Javadoc)
64+
* @see com.lambdaworks.redis.RedisClient#connectPubSub(com.lambdaworks.redis.codec.RedisCodec)
65+
*/
5466
@Override
5567
public <K, V> StatefulRedisPubSubConnection<K, V> connectPubSub(RedisCodec<K, V> codec) {
5668
return super.connectPubSub(codec);

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ public boolean isRedisSentinelAware() {
103103
return sentinelConfiguration != null;
104104
}
105105

106+
/*
107+
* (non-Javadoc)
108+
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
109+
*/
106110
@SuppressWarnings({ "rawtypes" })
107111
public void afterPropertiesSet() {
108112

@@ -136,6 +140,11 @@ private RedisURI createSimpleHostRedisURI() {
136140
return RedisURI.Builder.redis(hostName, port).withTimeout(timeout, TimeUnit.MILLISECONDS).build();
137141
}
138142

143+
/*
144+
* (non-Javadoc)
145+
* @see org.springframework.data.redis.connection.Pool#getResource()
146+
*/
147+
@Override
139148
@SuppressWarnings("unchecked")
140149
public StatefulConnection<byte[], byte[]> getResource() {
141150
try {
@@ -145,23 +154,41 @@ public StatefulConnection<byte[], byte[]> getResource() {
145154
}
146155
}
147156

157+
/*
158+
* (non-Javadoc)
159+
* @see org.springframework.data.redis.connection.Pool#returnBrokenResource(java.lang.Object)
160+
*/
161+
@Override
148162
public void returnBrokenResource(final StatefulConnection<byte[], byte[]> resource) {
163+
149164
try {
150165
internalPool.invalidateObject(resource);
151166
} catch (Exception e) {
152167
throw new PoolException("Could not invalidate the broken resource", e);
153168
}
154169
}
155170

171+
/*
172+
* (non-Javadoc)
173+
* @see org.springframework.data.redis.connection.Pool#returnResource(java.lang.Object)
174+
*/
175+
@Override
156176
public void returnResource(final StatefulConnection<byte[], byte[]> resource) {
177+
157178
try {
158179
internalPool.returnObject(resource);
159180
} catch (Exception e) {
160181
throw new PoolException("Could not return the resource to the pool", e);
161182
}
162183
}
163184

185+
/*
186+
* (non-Javadoc)
187+
* @see org.springframework.data.redis.connection.Pool#destroy()
188+
*/
189+
@Override
164190
public void destroy() {
191+
165192
try {
166193
client.shutdown();
167194
internalPool.close();
@@ -316,6 +343,10 @@ public LettuceFactory(RedisClient client, int dbIndex) {
316343
this.dbIndex = dbIndex;
317344
}
318345

346+
/*
347+
* (non-Javadoc)
348+
* @see org.apache.commons.pool2.BasePooledObjectFactory#activateObject(org.apache.commons.pool2.PooledObject)
349+
*/
319350
@Override
320351
public void activateObject(PooledObject<StatefulConnection<byte[], byte[]>> pooledObject) throws Exception {
321352

@@ -324,6 +355,11 @@ public void activateObject(PooledObject<StatefulConnection<byte[], byte[]>> pool
324355
}
325356
}
326357

358+
/*
359+
* (non-Javadoc)
360+
* @see org.apache.commons.pool2.BasePooledObjectFactory#destroyObject(org.apache.commons.pool2.PooledObject)
361+
*/
362+
@Override
327363
public void destroyObject(final PooledObject<StatefulConnection<byte[], byte[]>> obj) throws Exception {
328364
try {
329365
obj.getObject().close();
@@ -332,6 +368,11 @@ public void destroyObject(final PooledObject<StatefulConnection<byte[], byte[]>>
332368
}
333369
}
334370

371+
/*
372+
* (non-Javadoc)
373+
* @see org.apache.commons.pool2.BasePooledObjectFactory#validateObject(org.apache.commons.pool2.PooledObject)
374+
*/
375+
@Override
335376
public boolean validateObject(final PooledObject<StatefulConnection<byte[], byte[]>> obj) {
336377
try {
337378
if (obj.getObject() instanceof StatefulRedisConnection) {
@@ -343,11 +384,19 @@ public boolean validateObject(final PooledObject<StatefulConnection<byte[], byte
343384
}
344385
}
345386

387+
/*
388+
* (non-Javadoc)
389+
* @see org.apache.commons.pool2.BasePooledObjectFactory#create()
390+
*/
346391
@Override
347392
public StatefulConnection<byte[], byte[]> create() throws Exception {
348393
return client.connect(LettuceConnection.CODEC);
349394
}
350395

396+
/*
397+
* (non-Javadoc)
398+
* @see org.apache.commons.pool2.BasePooledObjectFactory#wrap(java.lang.Object)
399+
*/
351400
@Override
352401
public PooledObject<StatefulConnection<byte[], byte[]>> wrap(StatefulConnection<byte[], byte[]> obj) {
353402
return new DefaultPooledObject<StatefulConnection<byte[], byte[]>>(obj);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public Long del(byte[]... keys) {
298298

299299
Assert.noNullElements(keys, "Keys must not be null or contain null key!");
300300

301-
// Routing for mget is handled by lettuce itself.
301+
// Routing for mget is handled by lettuce.
302302
return super.del(keys);
303303
}
304304

@@ -876,7 +876,7 @@ public List<byte[]> mGet(byte[]... keys) {
876876

877877
Assert.notNull(keys, "Keys must not be null!");
878878

879-
// Routing for mget is handled by lettuce itself.
879+
// Routing for mget is handled by lettuce.
880880
return super.mGet(keys);
881881
}
882882

@@ -889,7 +889,7 @@ public void mSet(Map<byte[], byte[]> tuples) {
889889

890890
Assert.notNull(tuples, "Tuples must not be null!");
891891

892-
// Routing for msetnx is handled by lettuce itself.
892+
// Routing for mset is handled by lettuce.
893893
super.mSet(tuples);
894894
}
895895

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,16 +459,14 @@ public void openPipeline() {
459459
}
460460

461461
public List<Object> closePipeline() {
462+
462463
if (isPipelined) {
463464
isPipelined = false;
464465
List<com.lambdaworks.redis.protocol.RedisCommand<?, ?, ?>> futures = new ArrayList<com.lambdaworks.redis.protocol.RedisCommand<?, ?, ?>>();
465466
for (LettuceResult result : ppline) {
466467
futures.add(result.getResultHolder());
467468
}
468469

469-
// boolean done = LettuceFutures.awaitAll(timeout, TimeUnit.MILLISECONDS,
470-
// futures.toArray(new Command[futures.size()]));
471-
472470
try {
473471
boolean done = LettuceFutures.awaitAll(timeout, TimeUnit.MILLISECONDS,
474472
futures.toArray(new RedisFuture[futures.size()]));
@@ -479,14 +477,17 @@ public List<Object> closePipeline() {
479477

480478
if (done) {
481479
for (LettuceResult result : ppline) {
480+
482481
if (result.getResultHolder().getOutput().hasError()) {
482+
483483
Exception err = new InvalidDataAccessApiUsageException(result.getResultHolder().getOutput().getError());
484484
// remember only the first error
485485
if (problem == null) {
486486
problem = err;
487487
}
488488
results.add(err);
489489
} else if (!convertPipelineAndTxResults || !(result.isStatus())) {
490+
490491
try {
491492
results.add(result.get());
492493
} catch (DataAccessException e) {
@@ -3970,7 +3971,8 @@ protected RedisClusterAsyncCommands<byte[], byte[]> getAsyncDedicatedConnection(
39703971
return ((StatefulRedisClusterConnection<byte[], byte[]>) asyncDedicatedConn).async();
39713972
}
39723973

3973-
throw new IllegalStateException(String.format("%s is not a supported connection type.", asyncDedicatedConn.getClass().getName()));
3974+
throw new IllegalStateException(
3975+
String.format("%s is not a supported connection type.", asyncDedicatedConn.getClass().getName()));
39743976
}
39753977

39763978
protected StatefulConnection<byte[], byte[]> doGetAsyncDedicatedConnection() {
@@ -4004,7 +4006,8 @@ private RedisClusterCommands<byte[], byte[]> getDedicatedConnection() {
40044006
return ((StatefulRedisClusterConnection<byte[], byte[]>) asyncDedicatedConn).sync();
40054007
}
40064008

4007-
throw new IllegalStateException(String.format("%s is not a supported connection type.", asyncDedicatedConn.getClass().getName()));
4009+
throw new IllegalStateException(
4010+
String.format("%s is not a supported connection type.", asyncDedicatedConn.getClass().getName()));
40084011
}
40094012

40104013
private Future<Long> asyncBitOp(BitOperation op, byte[] destination, byte[]... keys) {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,19 +18,21 @@
1818

1919
import org.springframework.data.redis.connection.Pool;
2020

21-
import com.lambdaworks.redis.RedisClient;
21+
import com.lambdaworks.redis.AbstractRedisClient;
2222
import com.lambdaworks.redis.api.StatefulConnection;
2323

2424
/**
2525
* Pool of Lettuce {@link StatefulConnection}s
2626
*
2727
* @author Jennifer Hickey
28+
* @author Christoph Strobl
29+
* @author Mark Paluch
2830
*/
2931
public interface LettucePool extends Pool<StatefulConnection<byte[], byte[]>> {
3032

3133
/**
32-
* @return The {@link RedisClient} used to create pooled connections
34+
* @return The {@link AbstractRedisClient} used to create pooled connections
3335
*/
34-
RedisClient getClient();
36+
AbstractRedisClient getClient();
3537

3638
}

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.lambdaworks.redis.RedisURI.Builder;
3131
import com.lambdaworks.redis.resource.ClientResources;
3232
import com.lambdaworks.redis.sentinel.api.StatefulRedisSentinelConnection;
33+
import com.lambdaworks.redis.sentinel.api.sync.RedisSentinelCommands;
3334

3435
/**
3536
* @author Christoph Strobl
@@ -116,7 +117,7 @@ public void failover(NamedNode master) {
116117

117118
Assert.notNull(master, "Redis node master must not be 'null' for failover.");
118119
Assert.hasText(master.getName(), "Redis master name must not be 'null' or empty for failover.");
119-
connection.sync().failover(master.getName());
120+
getSentinelCommands().failover(master.getName());
120121
}
121122

122123
/*
@@ -126,7 +127,7 @@ public void failover(NamedNode master) {
126127
@Override
127128
public List<RedisServer> masters() {
128129
try {
129-
return LettuceConverters.toListOfRedisServer(connection.sync().masters());
130+
return LettuceConverters.toListOfRedisServer(getSentinelCommands().masters());
130131
} catch (Exception e) {
131132
throw EXCEPTION_TRANSLATION.translate(e);
132133
}
@@ -152,7 +153,7 @@ public List<RedisServer> slaves(String masterName) {
152153

153154
Assert.hasText(masterName, "Name of redis master cannot be 'null' or empty when loading slaves.");
154155
try {
155-
return LettuceConverters.toListOfRedisServer(connection.sync().slaves(masterName));
156+
return LettuceConverters.toListOfRedisServer(getSentinelCommands().slaves(masterName));
156157
} catch (Exception e) {
157158
throw EXCEPTION_TRANSLATION.translate(e);
158159
}
@@ -176,7 +177,7 @@ public void remove(NamedNode master) {
176177
public void remove(String masterName) {
177178

178179
Assert.hasText(masterName, "Name of redis master cannot be 'null' or empty when trying to remove.");
179-
connection.sync().remove(masterName);
180+
getSentinelCommands().remove(masterName);
180181
}
181182

182183
/*
@@ -191,7 +192,7 @@ public void monitor(RedisServer server) {
191192
Assert.hasText(server.getHost(), "Host must not be 'null' for server to monitor.");
192193
Assert.notNull(server.getPort(), "Port must not be 'null' for server to monitor.");
193194
Assert.notNull(server.getQuorum(), "Quorum must not be 'null' for server to monitor.");
194-
connection.sync().monitor(server.getName(), server.getHost(), server.getPort().intValue(),
195+
getSentinelCommands().monitor(server.getName(), server.getHost(), server.getPort().intValue(),
195196
server.getQuorum().intValue());
196197
}
197198

@@ -215,6 +216,10 @@ private void init() {
215216
}
216217
}
217218

219+
private RedisSentinelCommands<String, String> getSentinelCommands() {
220+
return connection.sync();
221+
}
222+
218223
private StatefulRedisSentinelConnection<String, String> connectSentinel() {
219224
return redisClient.connectSentinel();
220225
}

src/test/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClientTests.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,22 +15,23 @@
1515
*/
1616
package org.springframework.data.redis.connection.lettuce;
1717

18+
import org.junit.After;
19+
import org.junit.Before;
20+
import org.junit.Ignore;
21+
import org.junit.Test;
22+
1823
import com.lambdaworks.redis.RedisAsyncConnection;
1924
import com.lambdaworks.redis.RedisClient;
2025
import com.lambdaworks.redis.RedisException;
2126
import com.lambdaworks.redis.api.StatefulRedisConnection;
2227
import com.lambdaworks.redis.pubsub.StatefulRedisPubSubConnection;
2328

24-
import org.junit.After;
25-
import org.junit.Before;
26-
import org.junit.Ignore;
27-
import org.junit.Test;
28-
2929
/**
3030
* Integration test of {@link AuthenticatingRedisClient}. Enable requirepass and comment out the @Ignore to run.
3131
*
3232
* @author Jennifer Hickey
3333
* @author Thomas Darimont
34+
* @author Christoph Strobl
3435
*/
3536
@Ignore("Redis must have requirepass set to run this test")
3637
public class AuthenticatingRedisClientTests {

src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
119119
public void setUp() {
120120

121121
client = RedisClusterClient.create(LettuceTestClientResources.getSharedClientResources(),
122-
Builder.redis(CLUSTER_HOST, MASTER_NODE_1_PORT).withTimeout(100, TimeUnit.MILLISECONDS).build());
122+
Builder.redis(CLUSTER_HOST, MASTER_NODE_1_PORT).withTimeout(500, TimeUnit.MILLISECONDS).build());
123123
nativeConnection = client.connect().sync();
124124
clusterConnection = new LettuceClusterConnection(client);
125125
}

src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)