use of io.lettuce.core.ClientOptions in project spring-boot by spring-projects.
the class LettuceConnectionConfiguration method createClientOptions.
private ClientOptions createClientOptions() {
ClientOptions.Builder builder = initializeClientOptionsBuilder();
Duration connectTimeout = getProperties().getConnectTimeout();
if (connectTimeout != null) {
builder.socketOptions(SocketOptions.builder().connectTimeout(connectTimeout).build());
}
return builder.timeoutOptions(TimeoutOptions.enabled()).build();
}
use of io.lettuce.core.ClientOptions in project pay-publicapi by alphagov.
the class PublicApiModule method getRedisClient.
@Provides
@Singleton
public RedisClient getRedisClient() {
RedisClient client = RedisClient.create(configuration.getRedisConfiguration().getUrl());
SocketOptions socketOptions = SocketOptions.builder().connectTimeout(Duration.ofMillis(configuration.getRedisConfiguration().getConnectTimeout())).build();
ClientOptions clientOptions = ClientOptions.builder().socketOptions(socketOptions).build();
client.setOptions(clientOptions);
client.setDefaultTimeout(Duration.ofMillis(configuration.getRedisConfiguration().getCommandTimeout()));
return client;
}
use of io.lettuce.core.ClientOptions in project Sermant by huaweicloud.
the class RedisConnCluster method getConnectionFactory.
/**
* 往IOC容器中注册RedisConnectionFactory对象
* <p>
* 主要是针对redis集群的配置,暂时不实现,只实现单机版
*
* @return LettuceConnectionFactory
*/
@Bean(destroyMethod = "destroy")
@Conditional(value = { RedisClusterCondition.class })
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public LettuceConnectionFactory getConnectionFactory() {
// 集群配置
Map<String, Object> source = new HashMap<>();
source.put("spring.redis.cluster.nodes", nodes);
source.put("spring.redis.timeout", timeout);
source.put("spring.redis.database", database);
source.put("spring.redis.password", password);
RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration(new MapPropertySource("RedisClusterConfiguration", source));
redisClusterConfiguration.setMaxRedirects(redirects);
// 连接池配置
GenericObjectPoolConfig genericObjectPoolConfig = new GenericObjectPoolConfig();
genericObjectPoolConfig.setMaxIdle(maxIdle);
genericObjectPoolConfig.setMinIdle(minIdle);
genericObjectPoolConfig.setMaxTotal(maxActive);
genericObjectPoolConfig.setMaxWaitMillis(maxWait);
genericObjectPoolConfig.setMaxWaitMillis(MAX_WAIT_MS);
genericObjectPoolConfig.setTimeBetweenEvictionRunsMillis(EVICTION_RUNS_MS);
// 开启自适应集群拓扑刷新和周期拓扑刷新
ClusterTopologyRefreshOptions clusterTopologyRefreshOptions = ClusterTopologyRefreshOptions.builder().enableAllAdaptiveRefreshTriggers().adaptiveRefreshTriggersTimeout(Duration.ofSeconds(REFRESH_TRIGGERS_TIMEOUT)).enablePeriodicRefresh(Duration.ofSeconds(PERIODIC_REFRESH)).build();
ClientResources clientResources = DefaultClientResources.builder().dnsResolver(DnsResolvers.JVM_DEFAULT).build();
final SocketOptions socketOptions = SocketOptions.builder().connectTimeout(Duration.ofMillis(timeout)).build();
final ClientOptions clientOptions = ClusterClientOptions.builder().socketOptions(socketOptions).autoReconnect(true).topologyRefreshOptions(clusterTopologyRefreshOptions).build();
LettuceClientConfiguration clientConfig = LettucePoolingClientConfiguration.builder().poolConfig(genericObjectPoolConfig).clientOptions(clientOptions).clientResources(clientResources).commandTimeout(Duration.ofMillis(timeout)).build();
return new LettuceConnectionFactory(redisClusterConfiguration, clientConfig);
}
use of io.lettuce.core.ClientOptions in project lettuce-core by lettuce-io.
the class ClusterClientOptionsUnitTests method builderFromDefaultClientOptions.
@Test
void builderFromDefaultClientOptions() {
ClientOptions clientOptions = ClientOptions.builder().build();
ClusterClientOptions clusterClientOptions = ClusterClientOptions.builder(clientOptions).build();
assertThat(clusterClientOptions.getProtocolVersion()).isEqualTo(clusterClientOptions.getProtocolVersion());
assertThat(clusterClientOptions.getDisconnectedBehavior()).isEqualTo(clusterClientOptions.getDisconnectedBehavior());
assertThat(clusterClientOptions.getSslOptions()).isEqualTo(clusterClientOptions.getSslOptions());
assertThat(clusterClientOptions.getTimeoutOptions()).isEqualTo(clusterClientOptions.getTimeoutOptions());
assertThat(clusterClientOptions.getRequestQueueSize()).isEqualTo(clusterClientOptions.getRequestQueueSize());
assertThat(clusterClientOptions.isAutoReconnect()).isEqualTo(clusterClientOptions.isAutoReconnect());
assertThat(clusterClientOptions.isCloseStaleConnections()).isEqualTo(clusterClientOptions.isCloseStaleConnections());
assertThat(clusterClientOptions.isCancelCommandsOnReconnectFailure()).isEqualTo(clusterClientOptions.isCancelCommandsOnReconnectFailure());
assertThat(clusterClientOptions.isPublishOnScheduler()).isEqualTo(clusterClientOptions.isPublishOnScheduler());
assertThat(clusterClientOptions.isSuspendReconnectOnProtocolFailure()).isEqualTo(clusterClientOptions.isSuspendReconnectOnProtocolFailure());
assertThat(clusterClientOptions.getScriptCharset()).isEqualTo(clusterClientOptions.getScriptCharset());
assertThat(clusterClientOptions.mutate()).isNotNull();
}
use of io.lettuce.core.ClientOptions in project pulsar by apache.
the class RedisSession method create.
public static RedisSession create(RedisSinkConfig config) {
RedisSession redisSession;
final RedisCodec<byte[], byte[]> codec = new ByteArrayCodec();
final SocketOptions socketOptions = SocketOptions.builder().tcpNoDelay(config.isTcpNoDelay()).connectTimeout(Duration.ofMillis(config.getConnectTimeout())).keepAlive(config.isKeepAlive()).build();
final ClientMode clientMode;
try {
clientMode = ClientMode.valueOf(config.getClientMode().toUpperCase());
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Illegal Redis client mode, valid values are: " + Arrays.asList(ClientMode.values()));
}
List<RedisURI> redisURIs = redisURIs(config.getHostAndPorts(), config);
if (clientMode == ClientMode.STANDALONE) {
ClientOptions.Builder clientOptions = ClientOptions.builder().socketOptions(socketOptions).requestQueueSize(config.getRequestQueue()).autoReconnect(config.isAutoReconnect());
final RedisClient client = RedisClient.create(redisURIs.get(0));
client.setOptions(clientOptions.build());
final StatefulRedisConnection<byte[], byte[]> connection = client.connect(codec);
redisSession = new RedisSession(client, connection, connection.async());
} else if (clientMode == ClientMode.CLUSTER) {
ClusterClientOptions.Builder clientOptions = ClusterClientOptions.builder().requestQueueSize(config.getRequestQueue()).autoReconnect(config.isAutoReconnect());
final RedisClusterClient client = RedisClusterClient.create(redisURIs);
client.setOptions(clientOptions.build());
final StatefulRedisClusterConnection<byte[], byte[]> connection = client.connect(codec);
redisSession = new RedisSession(client, connection, connection.async());
} else {
throw new UnsupportedOperationException(String.format("%s is not supported", config.getClientMode()));
}
return redisSession;
}
Aggregations