use of com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig in project lcache by long172066912.
the class TestRedisCache2 method testPipeline.
@Test
public void testPipeline() {
BaseCacheExecutor baseCacheExecutor = CacheClientFactory.getCacheExecutor("friend", new LettuceConnectSourceConfig());
// while (true){
List<PipelineCmd> commands = new ArrayList<>();
for (int i = 0; i < 100; i++) {
commands.add(new PipelineGet("test"));
}
commands.add(new PipelineZremRangeByScore("test111", 0, System.currentTimeMillis()));
// 同步方式
List<Object> resList = baseCacheExecutor.pSync(commands);
System.out.println(JSON.toJSONString(resList));
// 异步方式
CompletableFuture<List<Object>> listCompletableFuture = baseCacheExecutor.pAsync(commands);
// }
}
use of com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig 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 com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig in project lcache by long172066912.
the class LettuceConnectionFactory method getLettuceClusterPubSubConnection.
/**
* 获取集群方式发布订阅连接
*
* @param lettuceClusterConnectSourceConfig
* @return
*/
public StatefulRedisClusterPubSubConnection<String, String> getLettuceClusterPubSubConnection(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 (StatefulRedisClusterPubSubConnection<String, String>) this.execute(() -> {
return client.connectPubSub();
});
}
use of com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig in project lcache by long172066912.
the class LettuceConnectionFactory method getLettuceClusterConnection.
/**
* 获取Lettuce集群
*
* @param lettuceClusterConnectSourceConfig
* @return
*/
public StatefulRedisClusterConnection<String, String> getLettuceClusterConnection(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 (StatefulRedisClusterConnection<String, String>) this.execute(() -> {
return client.connect();
});
}
use of com.lcache.extend.handle.redis.lettuce.config.LettuceConnectSourceConfig in project lcache by long172066912.
the class RedissonClientManager method getLettuceRedissonConfig.
/**
* Lettuce配置转Redisson配置
*
* @param cacheConfigModel
* @param cacheConfig
* @return
*/
private static Config getLettuceRedissonConfig(CacheConfigModel cacheConfigModel, BaseCacheConfig cacheConfig) {
Config config = new Config();
switch(cacheConfigModel.getConnectTypeEnum()) {
case SIMPLE:
LettuceConnectSourceConfig simpleConfig = (LettuceConnectSourceConfig) cacheConfig;
config.useSingleServer().setAddress("redis://" + simpleConfig.getHost() + ":" + simpleConfig.getPort()).setPassword(StringUtils.isNotBlank(simpleConfig.getPwd()) ? simpleConfig.getPwd() : null);
break;
case POOL:
LettuceConnectSourceConfig poolConfig = (LettuceConnectSourceConfig) cacheConfig;
config.useSingleServer().setAddress("redis://" + poolConfig.getHost() + ":" + poolConfig.getPort()).setPassword(StringUtils.isNotBlank(poolConfig.getPwd()) ? poolConfig.getPwd() : null);
break;
case SHARDED:
return null;
case CLUSTER:
LettuceClusterConnectSourceConfig clusterConfig = (LettuceClusterConnectSourceConfig) cacheConfig;
String pwd = "";
for (LettuceConnectSourceConfig hostAndPort : clusterConfig.getNodes()) {
config.useClusterServers().addNodeAddress("redis://" + hostAndPort.getHost() + ":" + hostAndPort.getPort());
pwd = hostAndPort.getPwd();
}
config.useClusterServers().setScanInterval(2000).setPassword(StringUtils.isNotBlank(pwd) ? pwd : null);
break;
case CLUSTER_POOL:
LettuceClusterConnectSourceConfig clusterPoolConfig = (LettuceClusterConnectSourceConfig) cacheConfig;
String pwd1 = "";
for (LettuceConnectSourceConfig hostAndPort : clusterPoolConfig.getNodes()) {
config.useClusterServers().addNodeAddress("redis://" + hostAndPort.getHost() + ":" + hostAndPort.getPort());
pwd1 = hostAndPort.getPwd();
}
config.useClusterServers().setScanInterval(2000).setPassword(StringUtils.isNotBlank(pwd1) ? pwd1 : null);
break;
default:
return null;
}
return config;
}
Aggregations