Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2011-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.jedis;
import redis.clients.jedis.*;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.util.Pool;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.springframework.core.convert.converter.Converter;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.ExceptionTranslationStrategy;
import org.springframework.data.redis.FallbackExceptionTranslationStrategy;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.*;
import org.springframework.data.redis.connection.convert.TransactionResultConverter;
import org.springframework.data.redis.connection.jedis.JedisResult.JedisResultBuilder;
import org.springframework.data.redis.connection.jedis.JedisResult.JedisStatusResult;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
* {@code RedisConnection} implementation on top of Jedis library.
*
* @author Costin Leau
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Thomas Darimont
* @author Jungtaek Lim
* @author Konstantin Shchepanovskyi
* @author David Liu
* @author Milan Agatonovic
* @author Mark Paluch
* @author Ninad Divadkar
* @author Guy Korland
* @author Dengliming
*/
public class JedisConnection extends AbstractRedisConnection {
private static final ExceptionTranslationStrategy EXCEPTION_TRANSLATION = new FallbackExceptionTranslationStrategy(
JedisConverters.exceptionConverter());
private final Jedis jedis;
private final JedisInvoker invoker = new JedisInvoker((directFunction, pipelineFunction, converter,
nullDefault) -> doInvoke(false, directFunction, pipelineFunction, converter, nullDefault));
private final JedisInvoker statusInvoker = new JedisInvoker((directFunction, pipelineFunction, converter,
nullDefault) -> doInvoke(true, directFunction, pipelineFunction, converter, nullDefault));
private final @Nullable Pool pool;
private final String clientName;
private final JedisClientConfig nodeConfig;
private final JedisClientConfig sentinelConfig;
private List pipelinedResults = new ArrayList<>();
private Queue>> txResults = new LinkedList<>();
private volatile @Nullable JedisSubscription subscription;
private volatile @Nullable Transaction transaction;
private volatile @Nullable Pipeline pipeline;
private boolean convertPipelineAndTxResults = true;
/**
* Constructs a new JedisConnection instance.
*
* @param jedis Jedis entity
*/
public JedisConnection(Jedis jedis) {
this(jedis, null, 0);
}
/**
* Constructs a new JedisConnection instance backed by a jedis pool.
*
* @param jedis
* @param pool can be null, if no pool is used
* @param dbIndex
*/
public JedisConnection(Jedis jedis, Pool pool, int dbIndex) {
this(jedis, pool, dbIndex, null);
}
/**
* Constructs a new JedisConnection instance backed by a jedis pool.
*
* @param jedis
* @param pool can be null, if no pool is used
* @param dbIndex
* @param clientName the client name, can be {@literal null}.
* @since 1.8
*/
protected JedisConnection(Jedis jedis, @Nullable Pool pool, int dbIndex, @Nullable String clientName) {
this(jedis, pool, createConfig(dbIndex, clientName), createConfig(dbIndex, clientName));
}
private static DefaultJedisClientConfig createConfig(int dbIndex, @Nullable String clientName) {
return DefaultJedisClientConfig.builder().database(dbIndex).clientName(clientName).build();
}
/**
* Constructs a new JedisConnection instance backed by a jedis pool.
*
* @param jedis
* @param pool can be null, if no pool is used
* @param nodeConfig node configuration
* @param sentinelConfig sentinel configuration
* @since 2.5
*/
protected JedisConnection(Jedis jedis, @Nullable Pool pool, JedisClientConfig nodeConfig,
JedisClientConfig sentinelConfig) {
this.jedis = jedis;
this.pool = pool;
this.clientName = nodeConfig.getClientName();
this.nodeConfig = nodeConfig;
this.sentinelConfig = sentinelConfig;
// select the db
// if this fail, do manual clean-up before propagating the exception
// as we're inside the constructor
if (nodeConfig.getDatabase() != jedis.getDB()) {
try {
select(nodeConfig.getDatabase());
} catch (DataAccessException ex) {
close();
throw ex;
}
}
}
@Nullable
private Object doInvoke(boolean status, Function directFunction,
Function> pipelineFunction, Converter