private int resolveDatabase() { if (ClassUtils.isPresent("io.lettuce.core.RedisClient", null) && this.redisConnectionFactory instanceof LettuceConnectionFactory) { return ((LettuceConnectionFactory) this.redisConnectionFactory).getDatabase(); } if (ClassUtils.isPresent("redis.clients.jedis.Jedis", null) && this.redisConnectionFactory instanceof JedisConnectionFactory) { return ((JedisConnectionFactory) this.redisConnectionFactory).getDatabase(); } return RedisOperationsSessionRepository.DEFAULT_DATABASE; }
/** * Obtain a connection from the associated {@link LettuceConnectionProvider}. * * @return the connection. */ private StatefulConnection<E, E> getNativeConnection() { try { StatefulConnection<E, E> connection = connectionProvider.getConnection(StatefulConnection.class); if (connection instanceof StatefulRedisConnection && getDatabase() > 0) { ((StatefulRedisConnection) connection).sync().select(getDatabase()); } return connection; } catch (RedisException e) { throw new RedisConnectionFailureException("Unable to connect to Redis", e); } }
private RedisURI getSentinelRedisURI() { RedisURI redisUri = LettuceConverters .sentinelConfigurationToRedisURI((org.springframework.data.redis.connection.RedisSentinelConfiguration) configuration); getRedisPassword().toOptional().ifPresent(redisUri::setPassword); clientConfiguration.getClientName().ifPresent(redisUri::setClientName); redisUri.setTimeout(clientConfiguration.getCommandTimeout()); redisUri.setDatabase(getDatabase()); return redisUri; }
public RedisConnection getConnection() { if (isClusterAware()) { return getClusterConnection(); } LettuceConnection connection; if (pool != null) { connection = new LettuceConnection(getSharedConnection(), getTimeout(), null, pool, getDatabase()); } else { connection = new LettuceConnection(getSharedConnection(), connectionProvider, getTimeout(), getDatabase()); } connection.setConvertPipelineAndTxResults(convertPipelineAndTxResults); return connection; }
/** * Create a {@link LettuceConnectionProvider} given {@link AbstractRedisClient} and {@link RedisCodec}. Configuration * of this connection factory specifies the type of the created connection provider. This method creates either a * {@link LettuceConnectionProvider} for either {@link RedisClient} or {@link RedisClusterClient}. Subclasses may * override this method to decorate the connection provider. * * @param client either {@link RedisClient} or {@link RedisClusterClient}, must not be {@literal null}. * @param codec used for connection creation, must not be {@literal null}. By default, a {@code byte[]} codec. * Reactive connections require a {@link java.nio.ByteBuffer} codec. * @return the connection provider. * @since 2.1 */ protected LettuceConnectionProvider doCreateConnectionProvider(AbstractRedisClient client, RedisCodec<?, ?> codec) { ReadFrom readFrom = getClientConfiguration().getReadFrom().orElse(null); if (isStaticMasterReplicaAware()) { List<RedisURI> nodes = ((RedisStaticMasterReplicaConfiguration) configuration).getNodes().stream() // .map(it -> createRedisURIAndApplySettings(it.getHostName(), it.getPort())) // .peek(it -> it.setDatabase(getDatabase())) // .collect(Collectors.toList()); return new StaticMasterReplicaConnectionProvider((RedisClient) client, codec, nodes, readFrom); } if (isClusterAware()) { return new ClusterConnectionProvider((RedisClusterClient) client, codec, readFrom); } return new StandaloneConnectionProvider((RedisClient) client, codec, readFrom); }
/** * Obtain a connection from the associated {@link LettuceConnectionProvider}. * * @return the connection. */ private StatefulConnection<E, E> getNativeConnection() { try { StatefulConnection<E, E> connection = connectionProvider.getConnection(StatefulConnection.class); if (connection instanceof StatefulRedisConnection && getDatabase() > 0) { ((StatefulRedisConnection) connection).sync().select(getDatabase()); } return connection; } catch (RedisException e) { throw new RedisConnectionFailureException("Unable to connect to Redis", e); } }
/** * Obtain a connection from the associated {@link LettuceConnectionProvider}. * * @return the connection. */ private StatefulConnection<E, E> getNativeConnection() { try { StatefulConnection<E, E> connection = connectionProvider.getConnection(StatefulConnection.class); if (connection instanceof StatefulRedisConnection && getDatabase() > 0) { ((StatefulRedisConnection) connection).sync().select(getDatabase()); } return connection; } catch (RedisException e) { throw new RedisConnectionFailureException("Unable to connect to Redis", e); } }
private RedisURI getSentinelRedisURI() { RedisURI redisUri = LettuceConverters .sentinelConfigurationToRedisURI((org.springframework.data.redis.connection.RedisSentinelConfiguration) configuration); getRedisPassword().toOptional().ifPresent(redisUri::setPassword); clientConfiguration.getClientName().ifPresent(redisUri::setClientName); redisUri.setTimeout(clientConfiguration.getCommandTimeout()); redisUri.setDatabase(getDatabase()); return redisUri; }
private RedisURI getSentinelRedisURI() { RedisURI redisUri = LettuceConverters .sentinelConfigurationToRedisURI((org.springframework.data.redis.connection.RedisSentinelConfiguration) configuration); getRedisPassword().toOptional().ifPresent(redisUri::setPassword); clientConfiguration.getClientName().ifPresent(redisUri::setClientName); redisUri.setTimeout(clientConfiguration.getCommandTimeout()); redisUri.setDatabase(getDatabase()); return redisUri; }
public RedisConnection getConnection() { if (isClusterAware()) { return getClusterConnection(); } LettuceConnection connection; if (pool != null) { connection = new LettuceConnection(getSharedConnection(), getTimeout(), null, pool, getDatabase()); } else { connection = new LettuceConnection(getSharedConnection(), connectionProvider, getTimeout(), getDatabase()); } connection.setConvertPipelineAndTxResults(convertPipelineAndTxResults); return connection; }
public RedisConnection getConnection() { if (isClusterAware()) { return getClusterConnection(); } LettuceConnection connection; if (pool != null) { connection = new LettuceConnection(getSharedConnection(), getTimeout(), null, pool, getDatabase()); } else { connection = new LettuceConnection(getSharedConnection(), connectionProvider, getTimeout(), getDatabase()); } connection.setConvertPipelineAndTxResults(convertPipelineAndTxResults); return connection; }
/** * Create a {@link LettuceConnectionProvider} given {@link AbstractRedisClient} and {@link RedisCodec}. Configuration * of this connection factory specifies the type of the created connection provider. This method creates either a * {@link LettuceConnectionProvider} for either {@link RedisClient} or {@link RedisClusterClient}. Subclasses may * override this method to decorate the connection provider. * * @param client either {@link RedisClient} or {@link RedisClusterClient}, must not be {@literal null}. * @param codec used for connection creation, must not be {@literal null}. By default, a {@code byte[]} codec. * Reactive connections require a {@link java.nio.ByteBuffer} codec. * @return the connection provider. * @since 2.1 */ protected LettuceConnectionProvider doCreateConnectionProvider(AbstractRedisClient client, RedisCodec<?, ?> codec) { ReadFrom readFrom = getClientConfiguration().getReadFrom().orElse(null); if (isStaticMasterReplicaAware()) { List<RedisURI> nodes = ((RedisStaticMasterReplicaConfiguration) configuration).getNodes().stream() // .map(it -> createRedisURIAndApplySettings(it.getHostName(), it.getPort())) // .peek(it -> it.setDatabase(getDatabase())) // .collect(Collectors.toList()); return new StaticMasterReplicaConnectionProvider((RedisClient) client, codec, nodes, readFrom); } if (isClusterAware()) { return new ClusterConnectionProvider((RedisClusterClient) client, codec, readFrom); } return new StandaloneConnectionProvider((RedisClient) client, codec, readFrom); }
/** * Create a {@link LettuceConnectionProvider} given {@link AbstractRedisClient} and {@link RedisCodec}. Configuration * of this connection factory specifies the type of the created connection provider. This method creates either a * {@link LettuceConnectionProvider} for either {@link RedisClient} or {@link RedisClusterClient}. Subclasses may * override this method to decorate the connection provider. * * @param client either {@link RedisClient} or {@link RedisClusterClient}, must not be {@literal null}. * @param codec used for connection creation, must not be {@literal null}. By default, a {@code byte[]} codec. * Reactive connections require a {@link java.nio.ByteBuffer} codec. * @return the connection provider. * @since 2.1 */ protected LettuceConnectionProvider doCreateConnectionProvider(AbstractRedisClient client, RedisCodec<?, ?> codec) { ReadFrom readFrom = getClientConfiguration().getReadFrom().orElse(null); if (isStaticMasterReplicaAware()) { List<RedisURI> nodes = ((RedisStaticMasterReplicaConfiguration) configuration).getNodes().stream() // .map(it -> createRedisURIAndApplySettings(it.getHostName(), it.getPort())) // .peek(it -> it.setDatabase(getDatabase())) // .collect(Collectors.toList()); return new StaticMasterReplicaConnectionProvider((RedisClient) client, codec, nodes, readFrom); } if (isClusterAware()) { return new ClusterConnectionProvider((RedisClusterClient) client, codec, readFrom); } return new StandaloneConnectionProvider((RedisClient) client, codec, readFrom); }