Skip to content

Commit 4be4ed0

Browse files
christophstroblmp911de
authored andcommitted
DATAREDIS-528 - Upgrade to Lettuce 4.2.2.
We now support Lettuce 4.2.2.Final. Using Lettuce requires Java 8. Original pull request: spring-projects#222.
1 parent 863e5b8 commit 4be4ed0

28 files changed

+660
-922
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<beanutils>1.9.2</beanutils>
2323
<xstream>1.4.8</xstream>
2424
<pool>2.2</pool>
25-
<lettuce>3.4.2.Final</lettuce>
25+
<lettuce>4.2.2.Final</lettuce>
2626
<jedis>2.9.0</jedis>
2727
<srp>0.7</srp>
2828
<jredis>06052013</jredis>

src/main/java/org/springframework/data/redis/connection/ClusterCommandExecutor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ public void destroy() throws Exception {
372372
if (executor instanceof DisposableBean) {
373373
((DisposableBean) executor).destroy();
374374
}
375+
376+
if (resourceProvider instanceof DisposableBean) {
377+
((DisposableBean) resourceProvider).destroy();
378+
}
375379
}
376380

377381
/**

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

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,44 @@
1515
*/
1616
package org.springframework.data.redis.connection.lettuce;
1717

18-
import com.lambdaworks.redis.RedisAsyncConnection;
1918
import com.lambdaworks.redis.RedisClient;
20-
import com.lambdaworks.redis.RedisConnection;
2119
import com.lambdaworks.redis.RedisURI;
20+
import com.lambdaworks.redis.api.StatefulRedisConnection;
21+
import com.lambdaworks.redis.api.async.RedisAsyncCommands;
2222
import com.lambdaworks.redis.codec.RedisCodec;
23-
import com.lambdaworks.redis.pubsub.RedisPubSubConnection;
23+
import com.lambdaworks.redis.pubsub.StatefulRedisPubSubConnection;
2424

2525
/**
2626
* Extension of {@link RedisClient} that calls auth on all new connections using the supplied credentials
2727
*
2828
* @author Jennifer Hickey
29-
* @author Mar Paluch
29+
* @author Mark Paluch
3030
* @author Christoph Strobl
3131
* @deprecated since 1.6 - Please use {@link RedisURI#setPassword(String)}
3232
*/
3333
@Deprecated
3434
public class AuthenticatingRedisClient extends RedisClient {
3535

36-
private String password;
37-
3836
public AuthenticatingRedisClient(String host, int port, String password) {
39-
super(host, port);
40-
this.password = password;
37+
super(null, RedisURI.builder().withHost(host).withPort(port).withPassword(password).build());
4138
}
4239

4340
public AuthenticatingRedisClient(String host, String password) {
44-
super(host);
45-
this.password = password;
41+
super(null, RedisURI.builder().withHost(host).withPassword(password).build());
4642
}
4743

4844
@Override
49-
public <K, V> RedisConnection<K, V> connect(RedisCodec<K, V> codec) {
50-
RedisConnection<K, V> conn = super.connect(codec);
51-
conn.auth(password);
52-
return conn;
45+
public <K, V> StatefulRedisConnection<K, V> connect(RedisCodec<K, V> codec) {
46+
return super.connect(codec);
5347
}
5448

5549
@Override
56-
public <K, V> RedisAsyncConnection<K, V> connectAsync(RedisCodec<K, V> codec) {
57-
RedisAsyncConnection<K, V> conn = super.connectAsync(codec);
58-
conn.auth(password);
59-
return conn;
50+
public <K, V> RedisAsyncCommands<K, V> connectAsync(RedisCodec<K, V> codec) {
51+
return super.connectAsync(codec);
6052
}
6153

6254
@Override
63-
public <K, V> RedisPubSubConnection<K, V> connectPubSub(RedisCodec<K, V> codec) {
64-
RedisPubSubConnection<K, V> conn = super.connectPubSub(codec);
65-
conn.auth(password);
66-
return conn;
55+
public <K, V> StatefulRedisPubSubConnection<K, V> connectPubSub(RedisCodec<K, V> codec) {
56+
return super.connectPubSub(codec);
6757
}
6858
}

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

Lines changed: 0 additions & 55 deletions
This file was deleted.

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

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
import org.springframework.util.Assert;
2929
import org.springframework.util.StringUtils;
3030

31-
import com.lambdaworks.redis.RedisAsyncConnection;
3231
import com.lambdaworks.redis.RedisClient;
3332
import com.lambdaworks.redis.RedisURI;
33+
import com.lambdaworks.redis.api.StatefulConnection;
34+
import com.lambdaworks.redis.api.StatefulRedisConnection;
3435
import com.lambdaworks.redis.resource.ClientResources;
3536

3637
/**
@@ -43,7 +44,7 @@
4344
public class DefaultLettucePool implements LettucePool, InitializingBean {
4445

4546
@SuppressWarnings("rawtypes") //
46-
private GenericObjectPool<RedisAsyncConnection> internalPool;
47+
private GenericObjectPool<StatefulConnection<byte[], byte[]>> internalPool;
4748
private RedisClient client;
4849
private int dbIndex = 0;
4950
private GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
@@ -112,7 +113,8 @@ public void afterPropertiesSet() {
112113
}
113114

114115
client.setDefaultTimeout(timeout, TimeUnit.MILLISECONDS);
115-
this.internalPool = new GenericObjectPool<RedisAsyncConnection>(new LettuceFactory(client, dbIndex), poolConfig);
116+
this.internalPool = new GenericObjectPool<StatefulConnection<byte[], byte[]>>(new LettuceFactory(client, dbIndex),
117+
poolConfig);
116118
}
117119

118120
/**
@@ -135,23 +137,23 @@ private RedisURI createSimpleHostRedisURI() {
135137
}
136138

137139
@SuppressWarnings("unchecked")
138-
public RedisAsyncConnection<byte[], byte[]> getResource() {
140+
public StatefulConnection<byte[], byte[]> getResource() {
139141
try {
140142
return internalPool.borrowObject();
141143
} catch (Exception e) {
142144
throw new PoolException("Could not get a resource from the pool", e);
143145
}
144146
}
145147

146-
public void returnBrokenResource(final RedisAsyncConnection<byte[], byte[]> resource) {
148+
public void returnBrokenResource(final StatefulConnection<byte[], byte[]> resource) {
147149
try {
148150
internalPool.invalidateObject(resource);
149151
} catch (Exception e) {
150152
throw new PoolException("Could not invalidate the broken resource", e);
151153
}
152154
}
153155

154-
public void returnResource(final RedisAsyncConnection<byte[], byte[]> resource) {
156+
public void returnResource(final StatefulConnection<byte[], byte[]> resource) {
155157
try {
156158
internalPool.returnObject(resource);
157159
} catch (Exception e) {
@@ -302,7 +304,7 @@ public void setClientResources(ClientResources clientResources) {
302304
}
303305

304306
@SuppressWarnings("rawtypes")
305-
private static class LettuceFactory extends BasePooledObjectFactory<RedisAsyncConnection> {
307+
private static class LettuceFactory extends BasePooledObjectFactory<StatefulConnection<byte[], byte[]>> {
306308

307309
private final RedisClient client;
308310

@@ -315,36 +317,40 @@ public LettuceFactory(RedisClient client, int dbIndex) {
315317
}
316318

317319
@Override
318-
public void activateObject(PooledObject<RedisAsyncConnection> pooledObject) throws Exception {
319-
pooledObject.getObject().select(dbIndex);
320+
public void activateObject(PooledObject<StatefulConnection<byte[], byte[]>> pooledObject) throws Exception {
321+
322+
if (pooledObject.getObject() instanceof StatefulRedisConnection) {
323+
((StatefulRedisConnection) pooledObject.getObject()).sync().select(dbIndex);
324+
}
320325
}
321326

322-
public void destroyObject(final PooledObject<RedisAsyncConnection> obj) throws Exception {
327+
public void destroyObject(final PooledObject<StatefulConnection<byte[], byte[]>> obj) throws Exception {
323328
try {
324329
obj.getObject().close();
325330
} catch (Exception e) {
326331
// Errors may happen if returning a broken resource
327332
}
328333
}
329334

330-
public boolean validateObject(final PooledObject<RedisAsyncConnection> obj) {
335+
public boolean validateObject(final PooledObject<StatefulConnection<byte[], byte[]>> obj) {
331336
try {
332-
obj.getObject().ping();
337+
if (obj.getObject() instanceof StatefulRedisConnection) {
338+
((StatefulRedisConnection) obj.getObject()).sync().ping();
339+
}
333340
return true;
334341
} catch (Exception e) {
335342
return false;
336343
}
337344
}
338345

339346
@Override
340-
public RedisAsyncConnection create() throws Exception {
341-
return client.connectAsync(LettuceConnection.CODEC);
347+
public StatefulConnection<byte[], byte[]> create() throws Exception {
348+
return client.connect(LettuceConnection.CODEC);
342349
}
343350

344351
@Override
345-
public PooledObject<RedisAsyncConnection> wrap(RedisAsyncConnection obj) {
346-
return new DefaultPooledObject<RedisAsyncConnection>(obj);
352+
public PooledObject<StatefulConnection<byte[], byte[]>> wrap(StatefulConnection<byte[], byte[]> obj) {
353+
return new DefaultPooledObject<StatefulConnection<byte[], byte[]>>(obj);
347354
}
348-
349355
}
350356
}

0 commit comments

Comments
 (0)