Remove deprecated LettucePool and deprecated methods.

See: #2273
Original Pull Request: #2276
This commit is contained in:
Mark Paluch
2022-02-22 15:02:49 +01:00
committed by Christoph Strobl
parent f1d528ffef
commit 91cfbf5470
16 changed files with 18 additions and 1190 deletions

View File

@@ -1,52 +0,0 @@
/*
* Copyright 2013-2022 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.lettuce;
import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.codec.RedisCodec;
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
/**
* Extension of {@link RedisClient} that calls auth on all new connections using the supplied credentials
*
* @author Jennifer Hickey
* @author Mark Paluch
* @author Christoph Strobl
* @deprecated since 1.6 - Please use {@link RedisURI#setPassword(String)}
*/
@Deprecated
public class AuthenticatingRedisClient extends RedisClient {
public AuthenticatingRedisClient(String host, int port, String password) {
super(null, RedisURI.builder().withHost(host).withPort(port).withPassword(password).build());
}
public AuthenticatingRedisClient(String host, String password) {
super(null, RedisURI.builder().withHost(host).withPassword(password).build());
}
@Override
public <K, V> StatefulRedisConnection<K, V> connect(RedisCodec<K, V> codec) {
return super.connect(codec);
}
@Override
public <K, V> StatefulRedisPubSubConnection<K, V> connectPubSub(RedisCodec<K, V> codec) {
return super.connectPubSub(codec);
}
}

View File

@@ -1,371 +0,0 @@
/*
* Copyright 2013-2022 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.lettuce;
import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulConnection;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.resource.ClientResources;
import java.time.Duration;
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.redis.connection.PoolException;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Default implementation of {@link LettucePool}.
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Mark Paluch
* @deprecated since 2.0, use pooling via {@link LettucePoolingClientConfiguration}.
*/
@Deprecated
public class DefaultLettucePool implements LettucePool, InitializingBean {
@SuppressWarnings("rawtypes") //
private @Nullable GenericObjectPool<StatefulConnection<byte[], byte[]>> internalPool;
private @Nullable RedisClient client;
private int dbIndex = 0;
private GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
private String hostName = "localhost";
private int port = 6379;
private @Nullable String password;
private long timeout = Duration.ofMinutes(1).toMillis();
private @Nullable RedisSentinelConfiguration sentinelConfiguration;
private @Nullable ClientResources clientResources;
/**
* Constructs a new <code>DefaultLettucePool</code> instance with default settings.
*/
public DefaultLettucePool() {}
/**
* Uses the {@link GenericObjectPoolConfig} defaults for configuring the connection pool
*
* @param hostName The Redis host
* @param port The Redis port
*/
public DefaultLettucePool(String hostName, int port) {
this.hostName = hostName;
this.port = port;
}
/**
* Uses the {@link RedisSentinelConfiguration} and {@link RedisClient} defaults for configuring the connection pool
* based on sentinels.
*
* @param sentinelConfiguration The Sentinel configuration
* @since 1.6
*/
public DefaultLettucePool(RedisSentinelConfiguration sentinelConfiguration) {
this.sentinelConfiguration = sentinelConfiguration;
}
/**
* Uses the {@link RedisClient} defaults for configuring the connection pool
*
* @param hostName The Redis host
* @param port The Redis port
* @param poolConfig The pool {@link GenericObjectPoolConfig}
*/
public DefaultLettucePool(String hostName, int port, GenericObjectPoolConfig poolConfig) {
this.hostName = hostName;
this.port = port;
this.poolConfig = poolConfig;
}
/**
* @return true when {@link RedisSentinelConfiguration} is present.
* @since 1.6
*/
public boolean isRedisSentinelAware() {
return sentinelConfiguration != null;
}
@SuppressWarnings({ "rawtypes" })
public void afterPropertiesSet() {
if (clientResources != null) {
this.client = RedisClient.create(clientResources, getRedisURI());
} else {
this.client = RedisClient.create(getRedisURI());
}
client.setDefaultTimeout(Duration.ofMillis(timeout));
this.internalPool = new GenericObjectPool<>(new LettuceFactory(client, dbIndex), poolConfig);
}
/**
* @return a RedisURI pointing either to a single Redis host or containing a set of sentinels.
*/
private RedisURI getRedisURI() {
RedisURI redisUri = isRedisSentinelAware()
? LettuceConverters.sentinelConfigurationToRedisURI(sentinelConfiguration) : createSimpleHostRedisURI();
if (StringUtils.hasText(password)) {
redisUri.setPassword(password);
}
return redisUri;
}
private RedisURI createSimpleHostRedisURI() {
return RedisURI.Builder.redis(hostName, port).withTimeout(Duration.ofMillis(timeout)).build();
}
@Override
@SuppressWarnings("unchecked")
public StatefulConnection<byte[], byte[]> getResource() {
try {
return internalPool.borrowObject();
} catch (Exception e) {
throw new PoolException("Could not get a resource from the pool", e);
}
}
@Override
public void returnBrokenResource(final StatefulConnection<byte[], byte[]> resource) {
try {
internalPool.invalidateObject(resource);
} catch (Exception e) {
throw new PoolException("Could not invalidate the broken resource", e);
}
}
@Override
public void returnResource(final StatefulConnection<byte[], byte[]> resource) {
try {
internalPool.returnObject(resource);
} catch (Exception e) {
throw new PoolException("Could not return the resource to the pool", e);
}
}
@Override
public void destroy() {
try {
client.shutdown();
internalPool.close();
} catch (Exception e) {
throw new PoolException("Could not destroy the pool", e);
}
}
/**
* @return The Redis client
*/
@Override
@Nullable
public RedisClient getClient() {
return client;
}
/**
* @return The pool configuration
*/
public GenericObjectPoolConfig getPoolConfig() {
return poolConfig;
}
/**
* @param poolConfig The pool configuration to use
*/
public void setPoolConfig(GenericObjectPoolConfig poolConfig) {
this.poolConfig = poolConfig;
}
/**
* Returns the index of the database.
*
* @return Returns the database index
*/
public int getDatabase() {
return dbIndex;
}
/**
* Sets the index of the database used by this connection pool. Default is 0.
*
* @param index database index
*/
public void setDatabase(int index) {
Assert.isTrue(index >= 0, "invalid DB index (a positive index required)");
this.dbIndex = index;
}
/**
* Returns the password used for authenticating with the Redis server.
*
* @return password for authentication
*/
@Nullable
public String getPassword() {
return password;
}
/**
* Sets the password used for authenticating with the Redis server.
*
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* Returns the current host.
*
* @return the host
*/
public String getHostName() {
return hostName;
}
/**
* Sets the host.
*
* @param host the host to set
*/
public void setHostName(String host) {
this.hostName = host;
}
/**
* Returns the current port.
*
* @return the port
*/
public int getPort() {
return port;
}
/**
* Sets the port.
*
* @param port the port to set
*/
public void setPort(int port) {
this.port = port;
}
/**
* Returns the connection timeout (in milliseconds).
*
* @return connection timeout
*/
public long getTimeout() {
return timeout;
}
/**
* Sets the connection timeout (in milliseconds).
*
* @param timeout connection timeout
*/
public void setTimeout(long timeout) {
this.timeout = timeout;
}
/**
* Get the {@link ClientResources} to reuse infrastructure.
*
* @return {@literal null} if not set.
* @since 1.7
*/
@Nullable
public ClientResources getClientResources() {
return clientResources;
}
/**
* Sets the {@link ClientResources} to reuse the client infrastructure. <br />
* Set to {@literal null} to not share resources.
*
* @param clientResources can be {@literal null}.
* @since 1.7
*/
public void setClientResources(ClientResources clientResources) {
this.clientResources = clientResources;
}
@SuppressWarnings("rawtypes")
private static class LettuceFactory extends BasePooledObjectFactory<StatefulConnection<byte[], byte[]>> {
private final RedisClient client;
private int dbIndex;
public LettuceFactory(RedisClient client, int dbIndex) {
super();
this.client = client;
this.dbIndex = dbIndex;
}
@Override
public void activateObject(PooledObject<StatefulConnection<byte[], byte[]>> pooledObject) throws Exception {
if (pooledObject.getObject() instanceof StatefulRedisConnection) {
((StatefulRedisConnection) pooledObject.getObject()).sync().select(dbIndex);
}
}
@Override
public void destroyObject(final PooledObject<StatefulConnection<byte[], byte[]>> obj) throws Exception {
try {
obj.getObject().close();
} catch (Exception e) {
// Errors may happen if returning a broken resource
}
}
@Override
public boolean validateObject(final PooledObject<StatefulConnection<byte[], byte[]>> obj) {
try {
if (obj.getObject() instanceof StatefulRedisConnection) {
((StatefulRedisConnection) obj.getObject()).sync().ping();
}
return true;
} catch (Exception e) {
return false;
}
}
@Override
public StatefulConnection<byte[], byte[]> create() throws Exception {
return client.connect(LettuceConnection.CODEC);
}
@Override
public PooledObject<StatefulConnection<byte[], byte[]>> wrap(StatefulConnection<byte[], byte[]> obj) {
return new DefaultPooledObject<>(obj);
}
}
}

View File

@@ -61,7 +61,7 @@ import org.springframework.util.ObjectUtils;
public class LettuceClusterConnection extends LettuceConnection implements DefaultedRedisClusterConnection {
static final ExceptionTranslationStrategy exceptionConverter = new PassThroughExceptionTranslationStrategy(
new LettuceExceptionConverter());
LettuceExceptionConverter.INSTANCE);
private final Log log = LogFactory.getLog(getClass());

View File

@@ -49,7 +49,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -93,7 +92,7 @@ public class LettuceConnection extends AbstractRedisConnection {
static final RedisCodec<byte[], byte[]> CODEC = ByteArrayCodec.INSTANCE;
private static final ExceptionTranslationStrategy EXCEPTION_TRANSLATION = new FallbackExceptionTranslationStrategy(
LettuceConverters.exceptionConverter());
LettuceExceptionConverter.INSTANCE);
private static final TypeHints typeHints = new TypeHints();
private final int defaultDbIndex;
@@ -161,20 +160,7 @@ public class LettuceConnection extends AbstractRedisConnection {
* @param client The {@link RedisClient} to use when instantiating a native connection
*/
public LettuceConnection(long timeout, RedisClient client) {
this(null, timeout, client, null);
}
/**
* Instantiates a new lettuce connection.
*
* @param timeout The connection timeout (in milliseconds) * @param client The {@link RedisClient} to use when
* instantiating a pub/sub connection
* @param pool The connection pool to use for all other native connections
* @deprecated since 2.0, use pooling via {@link LettucePoolingClientConfiguration}.
*/
@Deprecated
public LettuceConnection(long timeout, RedisClient client, LettucePool pool) {
this(null, timeout, client, pool);
this(null, timeout, client);
}
/**
@@ -187,25 +173,7 @@ public class LettuceConnection extends AbstractRedisConnection {
*/
public LettuceConnection(@Nullable StatefulRedisConnection<byte[], byte[]> sharedConnection, long timeout,
RedisClient client) {
this(sharedConnection, timeout, client, null);
}
/**
* Instantiates a new lettuce connection.
*
* @param sharedConnection A native connection that is shared with other {@link LettuceConnection}s. Should not be
* used for transactions or blocking operations
* @param timeout The connection timeout (in milliseconds)
* @param client The {@link RedisClient} to use when making pub/sub connections
* @param pool The connection pool to use for blocking and tx operations
* @deprecated since 2.0, use
* {@link #LettuceConnection(StatefulRedisConnection, LettuceConnectionProvider, long, int)}
*/
@Deprecated
public LettuceConnection(@Nullable StatefulRedisConnection<byte[], byte[]> sharedConnection, long timeout,
RedisClient client, @Nullable LettucePool pool) {
this(sharedConnection, timeout, client, pool, 0);
this(sharedConnection, timeout, client, 0);
}
/**
@@ -213,22 +181,13 @@ public class LettuceConnection extends AbstractRedisConnection {
* used for transactions or blocking operations.
* @param timeout The connection timeout (in milliseconds)
* @param client The {@link RedisClient} to use when making pub/sub connections.
* @param pool The connection pool to use for blocking and tx operations.
* @param defaultDbIndex The db index to use along with {@link RedisClient} when establishing a dedicated connection.
* @since 1.7
* @deprecated since 2.0, use
* {@link #LettuceConnection(StatefulRedisConnection, LettuceConnectionProvider, long, int)}
*/
@Deprecated
public LettuceConnection(@Nullable StatefulRedisConnection<byte[], byte[]> sharedConnection, long timeout,
@Nullable AbstractRedisClient client, @Nullable LettucePool pool, int defaultDbIndex) {
if (pool != null) {
this.connectionProvider = new LettucePoolConnectionProvider(pool);
} else {
this.connectionProvider = new StandaloneConnectionProvider((RedisClient) client, CODEC);
}
@Nullable AbstractRedisClient client, int defaultDbIndex) {
this.connectionProvider = new StandaloneConnectionProvider((RedisClient) client, CODEC);
this.asyncSharedConn = sharedConnection;
this.timeout = timeout;
this.defaultDbIndex = defaultDbIndex;
@@ -1248,43 +1207,6 @@ public class LettuceConnection extends AbstractRedisConnection {
}
}
static class LettucePoolConnectionProvider implements LettuceConnectionProvider {
private final LettucePool pool;
LettucePoolConnectionProvider(LettucePool pool) {
this.pool = pool;
}
@Override
public <T extends StatefulConnection<?, ?>> T getConnection(Class<T> connectionType) {
return connectionType.cast(pool.getResource());
}
@Override
public <T extends StatefulConnection<?, ?>> CompletionStage<T> getConnectionAsync(Class<T> connectionType) {
throw new UnsupportedOperationException("Async operations not supported!");
}
@Override
@SuppressWarnings("unchecked")
public void release(StatefulConnection<?, ?> connection) {
if (connection.isOpen()) {
if (connection instanceof StatefulRedisConnection) {
StatefulRedisConnection<?, ?> redisConnection = (StatefulRedisConnection<?, ?>) connection;
if (redisConnection.isMulti()) {
redisConnection.async().discard();
}
}
pool.returnResource((StatefulConnection<byte[], byte[]>) connection);
} else {
pool.returnBrokenResource((StatefulConnection<byte[], byte[]>) connection);
}
}
}
/**
* Strategy interface to control pipelining flush behavior. Lettuce writes (flushes) each command individually to the
* Redis connection. Flushing behavior can be customized to optimize for performance. Flushing can be either stateless

View File

@@ -104,7 +104,7 @@ public class LettuceConnectionFactory
implements InitializingBean, DisposableBean, RedisConnectionFactory, ReactiveRedisConnectionFactory {
private static final ExceptionTranslationStrategy EXCEPTION_TRANSLATION = new PassThroughExceptionTranslationStrategy(
LettuceConverters.exceptionConverter());
LettuceExceptionConverter.INSTANCE);
private final Log log = LogFactory.getLog(getClass());
private final LettuceClientConfiguration clientConfiguration;
@@ -117,7 +117,6 @@ public class LettuceConnectionFactory
private boolean eagerInitialization = false;
private @Nullable SharedConnection<byte[]> connection;
private @Nullable SharedConnection<ByteBuffer> reactiveConnection;
private @Nullable LettucePool pool;
/** Synchronization monitor for the shared Connection */
private final Object connectionMonitor = new Object();
private boolean convertPipelineAndTxResults = true;
@@ -198,17 +197,6 @@ public class LettuceConnectionFactory
this(clusterConfiguration, new MutableLettuceClientConfiguration());
}
/**
* @param pool
* @deprecated since 2.0, use pooling via {@link LettucePoolingClientConfiguration}.
*/
@Deprecated
public LettuceConnectionFactory(LettucePool pool) {
this(new MutableLettuceClientConfiguration());
this.pool = pool;
}
/**
* Constructs a new {@link LettuceConnectionFactory} instance using the given {@link RedisStandaloneConfiguration} and
* {@link LettuceClientConfiguration}.
@@ -405,8 +393,8 @@ public class LettuceConnectionFactory
return getClusterConnection();
}
LettuceConnection connection;
connection = doCreateLettuceConnection(getSharedConnection(), connectionProvider, getTimeout(), getDatabase());
LettuceConnection connection = doCreateLettuceConnection(getSharedConnection(), connectionProvider, getTimeout(),
getDatabase());
connection.setConvertPipelineAndTxResults(convertPipelineAndTxResults);
return connection;
}
@@ -1095,10 +1083,6 @@ public class LettuceConnectionFactory
private LettuceConnectionProvider createConnectionProvider(AbstractRedisClient client, RedisCodec<?, ?> codec) {
if (this.pool != null) {
return new LettucePoolConnectionProvider(this.pool);
}
LettuceConnectionProvider connectionProvider = doCreateConnectionProvider(client, codec);
if (this.clientConfiguration instanceof LettucePoolingClientConfiguration) {

View File

@@ -22,14 +22,12 @@ import io.lettuce.core.*;
import io.lettuce.core.cluster.models.partitions.Partitions;
import io.lettuce.core.cluster.models.partitions.RedisClusterNode.NodeFlag;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.springframework.core.convert.converter.Converter;
import org.springframework.dao.DataAccessException;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResult;
import org.springframework.data.geo.GeoResults;
@@ -53,7 +51,6 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Range.Boundar
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.redis.connection.SortParameters.Order;
import org.springframework.data.redis.connection.convert.Converters;
import org.springframework.data.redis.connection.convert.ListConverter;
import org.springframework.data.redis.connection.convert.LongToBooleanConverter;
import org.springframework.data.redis.connection.convert.StringToRedisClientInfoConverter;
import org.springframework.data.redis.core.KeyScanOptions;
@@ -65,7 +62,6 @@ import org.springframework.data.redis.domain.geo.BoxShape;
import org.springframework.data.redis.domain.geo.GeoReference;
import org.springframework.data.redis.domain.geo.GeoShape;
import org.springframework.data.redis.domain.geo.RadiusShape;
import org.springframework.data.redis.util.ByteUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@@ -84,12 +80,9 @@ import org.springframework.util.StringUtils;
* @author Chris Bono
* @author Vikas Garg
*/
@SuppressWarnings("ConstantConditions")
public abstract class LettuceConverters extends Converters {
private static final Converter<Exception, DataAccessException> EXCEPTION_CONVERTER = new LettuceExceptionConverter();
private static final ListConverter<GeoCoordinates, Point> GEO_COORDINATE_LIST_TO_POINT_LIST_CONVERTER;
private static final ListConverter<KeyValue<Object, Object>, Object> KEY_VALUE_LIST_UNWRAPPER;
public static final byte[] PLUS_BYTES;
public static final byte[] MINUS_BYTES;
public static final byte[] POSITIVE_INFINITY_BYTES;
@@ -104,31 +97,6 @@ public abstract class LettuceConverters extends Converters {
MINUS_BYTES = toBytes("-");
POSITIVE_INFINITY_BYTES = toBytes("+inf");
NEGATIVE_INFINITY_BYTES = toBytes("-inf");
GEO_COORDINATE_LIST_TO_POINT_LIST_CONVERTER = new ListConverter<>(LettuceConverters::geoCoordinatesToPoint);
KEY_VALUE_LIST_UNWRAPPER = new ListConverter<>(source -> source.getValueOrElse(null));
}
@Deprecated
public static List<Tuple> toTuple(List<byte[]> source) {
if (CollectionUtils.isEmpty(source)) {
return Collections.emptyList();
}
List<Tuple> tuples = new ArrayList<>();
Iterator<byte[]> it = source.iterator();
while (it.hasNext()) {
tuples.add(new DefaultTuple(it.next(), it.hasNext() ? Double.valueOf(toString(it.next())) : null));
}
return tuples;
}
@Deprecated
public static Converter<List<byte[]>, List<Tuple>> bytesListToTupleListConverter() {
return LettuceConverters::toTuple;
}
public static Point geoCoordinatesToPoint(@Nullable GeoCoordinates geoCoordinate) {
@@ -140,41 +108,6 @@ public abstract class LettuceConverters extends Converters {
return LettuceConverters::toListOfRedisClientInformation;
}
@Deprecated
public static Converter<Date, Long> dateToLong() {
return LettuceConverters::toLong;
}
@Deprecated
public static Converter<List<byte[]>, Set<byte[]>> bytesListToBytesSet() {
return LettuceConverters::toBytesSet;
}
@Deprecated
public static Converter<byte[], String> bytesToString() {
return LettuceConverters::toString;
}
@Deprecated
public static Converter<KeyValue<byte[], byte[]>, List<byte[]>> keyValueToBytesList() {
return LettuceConverters::toBytesList;
}
@Deprecated
public static Converter<Collection<byte[]>, List<byte[]>> bytesSetToBytesList() {
return LettuceConverters::toBytesList;
}
@Deprecated
public static Converter<Collection<byte[]>, List<byte[]>> bytesCollectionToBytesList() {
return LettuceConverters::toBytesList;
}
@Deprecated
public static Converter<List<ScoredValue<byte[]>>, Set<Tuple>> scoredValuesToTupleSet() {
return LettuceConverters::toTupleSet;
}
public static Converter<List<ScoredValue<byte[]>>, List<Tuple>> scoredValuesToTupleList() {
return source -> {
@@ -189,16 +122,6 @@ public abstract class LettuceConverters extends Converters {
};
}
@Deprecated
public static Converter<ScoredValue<byte[]>, Tuple> scoredValueToTuple() {
return LettuceConverters::toTuple;
}
@Deprecated
public static Converter<Exception, DataAccessException> exceptionConverter() {
return EXCEPTION_CONVERTER;
}
/**
* @return
* @sice 1.3
@@ -234,18 +157,6 @@ public abstract class LettuceConverters extends Converters {
return source != null ? new ArrayList<>(source) : null;
}
@Deprecated
public static Set<Tuple> toTupleSet(@Nullable List<ScoredValue<byte[]>> source) {
if (source == null) {
return null;
}
Set<Tuple> tuples = new LinkedHashSet<>(source.size());
for (ScoredValue<byte[]> value : source) {
tuples.add(LettuceConverters.toTuple(value));
}
return tuples;
}
public static Tuple toTuple(@Nullable ScoredValue<byte[]> source) {
return source != null && source.hasValue() ? new DefaultTuple(source.getValue(), Double.valueOf(source.getScore()))
: null;
@@ -300,11 +211,6 @@ public abstract class LettuceConverters extends Converters {
return target;
}
@Deprecated
public static Converter<List<byte[]>, Map<byte[], byte[]>> bytesListToMapConverter() {
return LettuceConverters::toMap;
}
public static SortArgs toSortArgs(SortParameters params) {
SortArgs args = new SortArgs();
@@ -346,28 +252,6 @@ public abstract class LettuceConverters extends Converters {
return StringToRedisClientInfoConverter.INSTANCE.convert(clientList.split("\\r?\\n"));
}
@Deprecated
public static byte[][] subarray(byte[][] input, int index) {
if (input.length > index) {
byte[][] output = new byte[input.length - index][];
System.arraycopy(input, index, output, 0, output.length);
return output;
}
return null;
}
@Deprecated
public static String boundaryToStringForZRange(Boundary boundary, String defaultValue) {
if (boundary == null || boundary.getValue() == null) {
return defaultValue;
}
return boundaryToString(boundary, "", "(");
}
private static String boundaryToString(Boundary boundary, String inclPrefix, String exclPrefix) {
String prefix = boundary.isIncluding() ? inclPrefix : exclPrefix;
@@ -639,66 +523,6 @@ public abstract class LettuceConverters extends Converters {
return toBytes(String.valueOf(source));
}
/**
* Converts a given {@link Boundary} to its binary representation suitable for {@literal ZRANGEBY*} commands, despite
* {@literal ZRANGEBYLEX}.
*
* @param boundary
* @param defaultValue
* @return
* @since 1.6
*/
@Deprecated
public static String boundaryToBytesForZRange(Boundary boundary, byte[] defaultValue) {
if (boundary == null || boundary.getValue() == null) {
return toString(defaultValue);
}
return boundaryToBytes(boundary, new byte[] {}, toBytes("("));
}
/**
* Converts a given {@link Boundary} to its binary representation suitable for ZRANGEBYLEX command.
*
* @param boundary
* @return
* @since 1.6
*/
@Deprecated
public static String boundaryToBytesForZRangeByLex(Boundary boundary, byte[] defaultValue) {
if (boundary == null || boundary.getValue() == null) {
return toString(defaultValue);
}
return boundaryToBytes(boundary, toBytes("["), toBytes("("));
}
private static String boundaryToBytes(Boundary boundary, byte[] inclPrefix, byte[] exclPrefix) {
byte[] prefix = boundary.isIncluding() ? inclPrefix : exclPrefix;
byte[] value = null;
if (boundary.getValue() instanceof byte[]) {
value = (byte[]) boundary.getValue();
} else if (boundary.getValue() instanceof Double) {
value = toBytes((Double) boundary.getValue());
} else if (boundary.getValue() instanceof Long) {
value = toBytes((Long) boundary.getValue());
} else if (boundary.getValue() instanceof Integer) {
value = toBytes((Integer) boundary.getValue());
} else if (boundary.getValue() instanceof String) {
value = toBytes((String) boundary.getValue());
} else {
throw new IllegalArgumentException(String.format("Cannot convert %s to binary format", boundary.getValue()));
}
ByteBuffer buffer = ByteBuffer.allocate(prefix.length + value.length);
buffer.put(prefix);
buffer.put(value);
return toString(ByteUtils.getBytes(buffer));
}
public static List<RedisClusterNode> partitionsToClusterNodes(@Nullable Partitions source) {
if (source == null) {
@@ -1050,25 +874,6 @@ public abstract class LettuceConverters extends Converters {
return GeoResultsConverterFactory.INSTANCE.forMetric(metric);
}
/**
* @return
* @since 1.8
*/
@Deprecated
public static ListConverter<io.lettuce.core.GeoCoordinates, Point> geoCoordinatesToPointConverter() {
return GEO_COORDINATE_LIST_TO_POINT_LIST_CONVERTER;
}
/**
* @return
* @since 2.0
*/
@SuppressWarnings("unchecked")
@Deprecated
public static <K, V> ListConverter<KeyValue<K, V>, V> keyValueListUnwrapper() {
return (ListConverter) KEY_VALUE_LIST_UNWRAPPER;
}
public static Converter<TransactionResult, List<Object>> transactionResultUnwrapper() {
return transactionResult -> transactionResult.stream().collect(Collectors.toList());
}

View File

@@ -40,6 +40,8 @@ import org.springframework.data.redis.RedisSystemException;
*/
public class LettuceExceptionConverter implements Converter<Exception, DataAccessException> {
static final LettuceExceptionConverter INSTANCE = new LettuceExceptionConverter();
public DataAccessException convert(Exception ex) {
if (ex instanceof ExecutionException || ex instanceof RedisCommandExecutionException) {

View File

@@ -71,7 +71,7 @@ class LettuceFutureUtils {
Throwable exceptionToUse = e;
if (e instanceof CompletionException) {
exceptionToUse = new LettuceExceptionConverter().convert((Exception) e.getCause());
exceptionToUse = LettuceExceptionConverter.INSTANCE.convert((Exception) e.getCause());
if (exceptionToUse == null) {
exceptionToUse = e.getCause();
}

View File

@@ -1,41 +0,0 @@
/*
* Copyright 2013-2022 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.lettuce;
import io.lettuce.core.AbstractRedisClient;
import io.lettuce.core.api.StatefulConnection;
import org.springframework.data.redis.connection.Pool;
import org.springframework.lang.Nullable;
/**
* Pool of Lettuce {@link StatefulConnection}s
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Mark Paluch
* @deprecated since 2.0, use pooling via {@link LettucePoolingClientConfiguration}.
*/
@Deprecated
public interface LettucePool extends Pool<StatefulConnection<byte[], byte[]>> {
/**
* @return The {@link AbstractRedisClient} used to create pooled connections
*/
@Nullable
AbstractRedisClient getClient();
}

View File

@@ -229,7 +229,7 @@ class LettuceReactiveRedisConnection implements ReactiveRedisConnection {
if (throwable instanceof RuntimeException) {
DataAccessException convertedException = LettuceConverters.exceptionConverter()
DataAccessException convertedException = LettuceExceptionConverter.INSTANCE
.convert((RuntimeException) throwable);
return convertedException != null ? convertedException : throwable;
}

View File

@@ -44,7 +44,7 @@ import org.springframework.util.Assert;
public class LettuceSentinelConnection implements RedisSentinelConnection {
private static final ExceptionTranslationStrategy EXCEPTION_TRANSLATION = new FallbackExceptionTranslationStrategy(
LettuceConverters.exceptionConverter());
LettuceExceptionConverter.INSTANCE);
private final LettuceConnectionProvider provider;
private StatefulRedisSentinelConnection<String, String> connection; // no that should not be null