use of io.lettuce.core.resource.DefaultClientResources in project lcache by long172066912.
the class LettuceConnectionFactory method getLettuceClusterPoolConnection.
/**
* 获取Lettuce集群连接池
*
* @param lettuceClusterConnectSourceConfig
* @return
*/
public GenericObjectPool getLettuceClusterPoolConnection(LettuceClusterConnectSourceConfig lettuceClusterConnectSourceConfig) {
// 设置线程
DefaultClientResources res = this.getDefaultClientResources(lettuceClusterConnectSourceConfig.getHosts().toString(), 0, lettuceClusterConnectSourceConfig.getCommonCacheConfig().getIoThreadPoolSize(), lettuceClusterConnectSourceConfig.getCommonCacheConfig().getComputationThreadPoolSize());
List<RedisURI> nodeConfigs = new ArrayList<>(lettuceClusterConnectSourceConfig.getNodes().size());
for (LettuceConnectSourceConfig redisSourceConfig : lettuceClusterConnectSourceConfig.getNodes()) {
nodeConfigs.add(this.getRedisUri(redisSourceConfig.getHost(), redisSourceConfig.getPort(), redisSourceConfig.getPwd(), redisSourceConfig.getDatabase(), redisSourceConfig.getTimeout()));
}
RedisClusterClient client = RedisClusterClient.create(res, nodeConfigs);
client.setDefaultTimeout(Duration.ofMillis(lettuceClusterConnectSourceConfig.getSoTimeout()));
client.setOptions(CacheConfigBuildUtils.getClusterClientOptions(lettuceClusterConnectSourceConfig));
return (GenericObjectPool) this.execute(() -> {
return ConnectionPoolSupport.createGenericObjectPool(() -> client.connect(), CacheConfigBuildUtils.getJedisPoolConfig(lettuceClusterConnectSourceConfig.getCommonCacheConfig()));
});
}
use of io.lettuce.core.resource.DefaultClientResources in project lcache by long172066912.
the class LettuceConnectionFactory method getLettuceConnectionByPool.
/**
* 获取Lettuce连接池
*
* @param redisSourceConfig
* @return
*/
public GenericObjectPool getLettuceConnectionByPool(LettuceConnectSourceConfig redisSourceConfig) {
// 设置线程
DefaultClientResources res = this.getDefaultClientResources(redisSourceConfig.getHost(), redisSourceConfig.getPort(), redisSourceConfig.getCommonCacheConfig().getIoThreadPoolSize(), redisSourceConfig.getCommonCacheConfig().getComputationThreadPoolSize());
RedisClient client = RedisClient.create(res, this.getRedisUri(redisSourceConfig.getHost(), redisSourceConfig.getPort(), redisSourceConfig.getPwd(), redisSourceConfig.getDatabase(), redisSourceConfig.getTimeout()));
client.setOptions(CacheConfigBuildUtils.getClientOptions(redisSourceConfig));
client.setDefaultTimeout(Duration.ofMillis(redisSourceConfig.getSoTimeout()));
return (GenericObjectPool) this.execute(() -> {
return ConnectionPoolSupport.createGenericObjectPool(() -> client.connect(), CacheConfigBuildUtils.getJedisPoolConfig(redisSourceConfig.getCommonCacheConfig()));
});
}
use of io.lettuce.core.resource.DefaultClientResources in project lettuce-core by lettuce-io.
the class RedisClientIntegrationTests method reuseClientConnectionsShutdownTwoClients.
@Test
void reuseClientConnectionsShutdownTwoClients() throws Exception {
// given
DefaultClientResources clientResources = DefaultClientResources.create();
Map<Class<? extends EventExecutorGroup>, EventExecutorGroup> eventLoopGroups = getExecutors(clientResources);
RedisClient redisClient1 = newClient(clientResources);
RedisClient redisClient2 = newClient(clientResources);
connectAndClose(redisClient1);
connectAndClose(redisClient2);
// when
EventExecutorGroup executor = eventLoopGroups.values().iterator().next();
redisClient1.shutdown(0, 0, TimeUnit.MILLISECONDS);
assertThat(executor.isShutdown()).isFalse();
connectAndClose(redisClient2);
redisClient2.shutdown(0, 0, TimeUnit.MILLISECONDS);
// then
assertThat(eventLoopGroups).isEmpty();
assertThat(executor.isShutdown()).isTrue();
assertThat(clientResources.eventExecutorGroup().isShuttingDown()).isFalse();
// cleanup
TestFutures.awaitOrTimeout(clientResources.shutdown(0, 0, TimeUnit.MILLISECONDS));
assertThat(clientResources.eventExecutorGroup().isShuttingDown()).isTrue();
}
use of io.lettuce.core.resource.DefaultClientResources in project spring-boot by spring-projects.
the class RedisAutoConfigurationTests method testCustomizeClientResources.
@Test
void testCustomizeClientResources() {
Tracing tracing = mock(Tracing.class);
this.contextRunner.withBean(ClientResourcesBuilderCustomizer.class, () -> (builder) -> builder.tracing(tracing)).run((context) -> {
DefaultClientResources clientResources = context.getBean(DefaultClientResources.class);
assertThat(clientResources.tracing()).isEqualTo(tracing);
});
}
use of io.lettuce.core.resource.DefaultClientResources in project hazelcast-simulator by hazelcast.
the class LettuceCluster5Driver method startDriverInstance.
@Override
public void startDriverInstance() throws Exception {
String workerType = get("WORKER_TYPE");
if ("javaclient".equals(workerType)) {
String[] uris = get("URI").split(",");
DefaultClientResources clientResources = //
DefaultClientResources.builder().dnsResolver(// Does not cache DNS lookups
new DirContextDnsResolver()).build();
List<RedisURI> nodes = new LinkedList<>();
for (String uri : uris) {
nodes.add(RedisURI.create(uri));
}
// client = RedisClient.create();
//
// StatefulRedisMasterReplicaConnection<String, String> connection = MasterReplica
// .connect(client, new Utf8StringCodec(), nodes);
// connection.setReadFrom(ReadFrom.MASTER_PREFERRED);
client = RedisClusterClient.create(nodes);
// client = RedisClient.create(clientResources, get("URI"));
}
}
Aggregations