DATAREDIS-528 - Polishing.
Extend date ranges in license headers. Add author tags. Update documentation. Original pull request: #222.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2016 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.
|
||||
@@ -41,16 +41,28 @@ public class AuthenticatingRedisClient extends RedisClient {
|
||||
super(null, RedisURI.builder().withHost(host).withPassword(password).build());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.lambdaworks.redis.RedisClient#connect(com.lambdaworks.redis.codec.RedisCodec)
|
||||
*/
|
||||
@Override
|
||||
public <K, V> StatefulRedisConnection<K, V> connect(RedisCodec<K, V> codec) {
|
||||
return super.connect(codec);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.lambdaworks.redis.RedisClient#connectAsync(com.lambdaworks.redis.codec.RedisCodec)
|
||||
*/
|
||||
@Override
|
||||
public <K, V> RedisAsyncCommands<K, V> connectAsync(RedisCodec<K, V> codec) {
|
||||
return super.connectAsync(codec);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.lambdaworks.redis.RedisClient#connectPubSub(com.lambdaworks.redis.codec.RedisCodec)
|
||||
*/
|
||||
@Override
|
||||
public <K, V> StatefulRedisPubSubConnection<K, V> connectPubSub(RedisCodec<K, V> codec) {
|
||||
return super.connectPubSub(codec);
|
||||
|
||||
@@ -103,6 +103,10 @@ public class DefaultLettucePool implements LettucePool, InitializingBean {
|
||||
return sentinelConfiguration != null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public void afterPropertiesSet() {
|
||||
|
||||
@@ -136,6 +140,11 @@ public class DefaultLettucePool implements LettucePool, InitializingBean {
|
||||
return RedisURI.Builder.redis(hostName, port).withTimeout(timeout, TimeUnit.MILLISECONDS).build();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.Pool#getResource()
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public StatefulConnection<byte[], byte[]> getResource() {
|
||||
try {
|
||||
@@ -145,7 +154,13 @@ public class DefaultLettucePool implements LettucePool, InitializingBean {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.Pool#returnBrokenResource(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public void returnBrokenResource(final StatefulConnection<byte[], byte[]> resource) {
|
||||
|
||||
try {
|
||||
internalPool.invalidateObject(resource);
|
||||
} catch (Exception e) {
|
||||
@@ -153,7 +168,13 @@ public class DefaultLettucePool implements LettucePool, InitializingBean {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.Pool#returnResource(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public void returnResource(final StatefulConnection<byte[], byte[]> resource) {
|
||||
|
||||
try {
|
||||
internalPool.returnObject(resource);
|
||||
} catch (Exception e) {
|
||||
@@ -161,7 +182,13 @@ public class DefaultLettucePool implements LettucePool, InitializingBean {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.Pool#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
try {
|
||||
client.shutdown();
|
||||
internalPool.close();
|
||||
@@ -316,6 +343,10 @@ public class DefaultLettucePool implements LettucePool, InitializingBean {
|
||||
this.dbIndex = dbIndex;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.apache.commons.pool2.BasePooledObjectFactory#activateObject(org.apache.commons.pool2.PooledObject)
|
||||
*/
|
||||
@Override
|
||||
public void activateObject(PooledObject<StatefulConnection<byte[], byte[]>> pooledObject) throws Exception {
|
||||
|
||||
@@ -324,6 +355,11 @@ public class DefaultLettucePool implements LettucePool, InitializingBean {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.apache.commons.pool2.BasePooledObjectFactory#destroyObject(org.apache.commons.pool2.PooledObject)
|
||||
*/
|
||||
@Override
|
||||
public void destroyObject(final PooledObject<StatefulConnection<byte[], byte[]>> obj) throws Exception {
|
||||
try {
|
||||
obj.getObject().close();
|
||||
@@ -332,6 +368,11 @@ public class DefaultLettucePool implements LettucePool, InitializingBean {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.apache.commons.pool2.BasePooledObjectFactory#validateObject(org.apache.commons.pool2.PooledObject)
|
||||
*/
|
||||
@Override
|
||||
public boolean validateObject(final PooledObject<StatefulConnection<byte[], byte[]>> obj) {
|
||||
try {
|
||||
if (obj.getObject() instanceof StatefulRedisConnection) {
|
||||
@@ -343,11 +384,19 @@ public class DefaultLettucePool implements LettucePool, InitializingBean {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.apache.commons.pool2.BasePooledObjectFactory#create()
|
||||
*/
|
||||
@Override
|
||||
public StatefulConnection<byte[], byte[]> create() throws Exception {
|
||||
return client.connect(LettuceConnection.CODEC);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.apache.commons.pool2.BasePooledObjectFactory#wrap(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public PooledObject<StatefulConnection<byte[], byte[]>> wrap(StatefulConnection<byte[], byte[]> obj) {
|
||||
return new DefaultPooledObject<StatefulConnection<byte[], byte[]>>(obj);
|
||||
|
||||
@@ -298,7 +298,7 @@ public class LettuceClusterConnection extends LettuceConnection
|
||||
|
||||
Assert.noNullElements(keys, "Keys must not be null or contain null key!");
|
||||
|
||||
// Routing for mget is handled by lettuce itself.
|
||||
// Routing for mget is handled by lettuce.
|
||||
return super.del(keys);
|
||||
}
|
||||
|
||||
@@ -876,7 +876,7 @@ public class LettuceClusterConnection extends LettuceConnection
|
||||
|
||||
Assert.notNull(keys, "Keys must not be null!");
|
||||
|
||||
// Routing for mget is handled by lettuce itself.
|
||||
// Routing for mget is handled by lettuce.
|
||||
return super.mGet(keys);
|
||||
}
|
||||
|
||||
@@ -889,7 +889,7 @@ public class LettuceClusterConnection extends LettuceConnection
|
||||
|
||||
Assert.notNull(tuples, "Tuples must not be null!");
|
||||
|
||||
// Routing for msetnx is handled by lettuce itself.
|
||||
// Routing for mset is handled by lettuce.
|
||||
super.mSet(tuples);
|
||||
}
|
||||
|
||||
|
||||
@@ -459,6 +459,7 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
}
|
||||
|
||||
public List<Object> closePipeline() {
|
||||
|
||||
if (isPipelined) {
|
||||
isPipelined = false;
|
||||
List<com.lambdaworks.redis.protocol.RedisCommand<?, ?, ?>> futures = new ArrayList<com.lambdaworks.redis.protocol.RedisCommand<?, ?, ?>>();
|
||||
@@ -466,9 +467,6 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
futures.add(result.getResultHolder());
|
||||
}
|
||||
|
||||
// boolean done = LettuceFutures.awaitAll(timeout, TimeUnit.MILLISECONDS,
|
||||
// futures.toArray(new Command[futures.size()]));
|
||||
|
||||
try {
|
||||
boolean done = LettuceFutures.awaitAll(timeout, TimeUnit.MILLISECONDS,
|
||||
futures.toArray(new RedisFuture[futures.size()]));
|
||||
@@ -479,7 +477,9 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
|
||||
if (done) {
|
||||
for (LettuceResult result : ppline) {
|
||||
|
||||
if (result.getResultHolder().getOutput().hasError()) {
|
||||
|
||||
Exception err = new InvalidDataAccessApiUsageException(result.getResultHolder().getOutput().getError());
|
||||
// remember only the first error
|
||||
if (problem == null) {
|
||||
@@ -487,6 +487,7 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
}
|
||||
results.add(err);
|
||||
} else if (!convertPipelineAndTxResults || !(result.isStatus())) {
|
||||
|
||||
try {
|
||||
results.add(result.get());
|
||||
} catch (DataAccessException e) {
|
||||
@@ -3970,7 +3971,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
return ((StatefulRedisClusterConnection<byte[], byte[]>) asyncDedicatedConn).async();
|
||||
}
|
||||
|
||||
throw new IllegalStateException(String.format("%s is not a supported connection type.", asyncDedicatedConn.getClass().getName()));
|
||||
throw new IllegalStateException(
|
||||
String.format("%s is not a supported connection type.", asyncDedicatedConn.getClass().getName()));
|
||||
}
|
||||
|
||||
protected StatefulConnection<byte[], byte[]> doGetAsyncDedicatedConnection() {
|
||||
@@ -4004,7 +4006,8 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
return ((StatefulRedisClusterConnection<byte[], byte[]>) asyncDedicatedConn).sync();
|
||||
}
|
||||
|
||||
throw new IllegalStateException(String.format("%s is not a supported connection type.", asyncDedicatedConn.getClass().getName()));
|
||||
throw new IllegalStateException(
|
||||
String.format("%s is not a supported connection type.", asyncDedicatedConn.getClass().getName()));
|
||||
}
|
||||
|
||||
private Future<Long> asyncBitOp(BitOperation op, byte[] destination, byte[]... keys) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2016 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.
|
||||
@@ -18,19 +18,21 @@ package org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import org.springframework.data.redis.connection.Pool;
|
||||
|
||||
import com.lambdaworks.redis.RedisClient;
|
||||
import com.lambdaworks.redis.AbstractRedisClient;
|
||||
import com.lambdaworks.redis.api.StatefulConnection;
|
||||
|
||||
/**
|
||||
* Pool of Lettuce {@link StatefulConnection}s
|
||||
*
|
||||
* @author Jennifer Hickey
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public interface LettucePool extends Pool<StatefulConnection<byte[], byte[]>> {
|
||||
|
||||
/**
|
||||
* @return The {@link RedisClient} used to create pooled connections
|
||||
* @return The {@link AbstractRedisClient} used to create pooled connections
|
||||
*/
|
||||
RedisClient getClient();
|
||||
AbstractRedisClient getClient();
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.lambdaworks.redis.RedisClient;
|
||||
import com.lambdaworks.redis.RedisURI.Builder;
|
||||
import com.lambdaworks.redis.resource.ClientResources;
|
||||
import com.lambdaworks.redis.sentinel.api.StatefulRedisSentinelConnection;
|
||||
import com.lambdaworks.redis.sentinel.api.sync.RedisSentinelCommands;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
@@ -116,7 +117,7 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
|
||||
|
||||
Assert.notNull(master, "Redis node master must not be 'null' for failover.");
|
||||
Assert.hasText(master.getName(), "Redis master name must not be 'null' or empty for failover.");
|
||||
connection.sync().failover(master.getName());
|
||||
getSentinelCommands().failover(master.getName());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -126,7 +127,7 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
|
||||
@Override
|
||||
public List<RedisServer> masters() {
|
||||
try {
|
||||
return LettuceConverters.toListOfRedisServer(connection.sync().masters());
|
||||
return LettuceConverters.toListOfRedisServer(getSentinelCommands().masters());
|
||||
} catch (Exception e) {
|
||||
throw EXCEPTION_TRANSLATION.translate(e);
|
||||
}
|
||||
@@ -152,7 +153,7 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
|
||||
|
||||
Assert.hasText(masterName, "Name of redis master cannot be 'null' or empty when loading slaves.");
|
||||
try {
|
||||
return LettuceConverters.toListOfRedisServer(connection.sync().slaves(masterName));
|
||||
return LettuceConverters.toListOfRedisServer(getSentinelCommands().slaves(masterName));
|
||||
} catch (Exception e) {
|
||||
throw EXCEPTION_TRANSLATION.translate(e);
|
||||
}
|
||||
@@ -176,7 +177,7 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
|
||||
public void remove(String masterName) {
|
||||
|
||||
Assert.hasText(masterName, "Name of redis master cannot be 'null' or empty when trying to remove.");
|
||||
connection.sync().remove(masterName);
|
||||
getSentinelCommands().remove(masterName);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -191,7 +192,7 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
|
||||
Assert.hasText(server.getHost(), "Host must not be 'null' for server to monitor.");
|
||||
Assert.notNull(server.getPort(), "Port must not be 'null' for server to monitor.");
|
||||
Assert.notNull(server.getQuorum(), "Quorum must not be 'null' for server to monitor.");
|
||||
connection.sync().monitor(server.getName(), server.getHost(), server.getPort().intValue(),
|
||||
getSentinelCommands().monitor(server.getName(), server.getHost(), server.getPort().intValue(),
|
||||
server.getQuorum().intValue());
|
||||
}
|
||||
|
||||
@@ -215,6 +216,10 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
|
||||
}
|
||||
}
|
||||
|
||||
private RedisSentinelCommands<String, String> getSentinelCommands() {
|
||||
return connection.sync();
|
||||
}
|
||||
|
||||
private StatefulRedisSentinelConnection<String, String> connectSentinel() {
|
||||
return redisClient.connectSentinel();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user