use of com.lcache.config.BaseCacheConfig in project lcache by long172066912.
the class LettuceHandlesPostProcessor method onFail.
@Override
public void onFail(CacheHandleProcessorModel cacheHandleProcessorModel) {
/**
* 如果是lua脚本异常,重新缓存
*/
if (cacheHandleProcessorModel.getE() instanceof RedisNoScriptException) {
// 获取执行器调用脚本缓存操作
CacheExecutorFactory.getCacheExecutor(null, cacheHandleProcessorModel.getCacheConfigModel()).loadLuaScripts();
}
// Lettuce非连接池方式增加连接重置功能
if (cacheHandleProcessorModel.getCacheConfigModel().getConnectTypeEnum().equals(ConnectTypeEnum.SIMPLE) && cacheHandleProcessorModel.getE().getMessage().contains(CONNECTION_CLOSE_ERROR)) {
// 重置连接
try {
synchronized (cacheHandleProcessorModel.getCacheConfigModel()) {
// 获取配置
BaseCacheConfig config = CacheExecutorFactory.getRedisSourceConfig(cacheHandleProcessorModel.getCacheConfigModel());
// 判断连接是否有效
LettuceConnectResource resource = (LettuceConnectResource) RedisConnectionManager.getConnectionResource(cacheHandleProcessorModel.getCacheConfigModel(), config).getResource();
if (!resource.getStatefulRedisConnection().isOpen()) {
// 重置连接
RedisConnectionManager.resetConnectionResource(cacheHandleProcessorModel.getCacheConfigModel(), config);
}
}
} catch (Exception e) {
CacheExceptionFactory.addErrorLog("LettuceHandlesPostProcessor reset connection fail !", e);
}
}
}
use of com.lcache.config.BaseCacheConfig in project lcache by long172066912.
the class RedissonClientManager method getJedisRedissonConfig.
/**
* Jedis配置转Redisson配置
*
* @param cacheConfigModel
* @param cacheConfig
* @return
*/
private static Config getJedisRedissonConfig(CacheConfigModel cacheConfigModel, BaseCacheConfig cacheConfig) {
Config config = new Config();
switch(cacheConfigModel.getConnectTypeEnum()) {
case SIMPLE:
JedisConnectSourceConfig simpleConfig = (JedisConnectSourceConfig) cacheConfig;
config.useSingleServer().setAddress("redis://" + simpleConfig.getHost() + ":" + simpleConfig.getPort()).setPassword(StringUtils.isNotBlank(simpleConfig.getPwd()) ? simpleConfig.getPwd() : null);
break;
case POOL:
JedisConnectSourceConfig poolConfig = (JedisConnectSourceConfig) cacheConfig;
config.useSingleServer().setAddress("redis://" + poolConfig.getHost() + ":" + poolConfig.getPort()).setPassword(StringUtils.isNotBlank(poolConfig.getPwd()) ? poolConfig.getPwd() : null);
break;
case SHARDED:
return null;
case CLUSTER:
JedisClusterConnectSourceConfig clusterConfig = (JedisClusterConnectSourceConfig) cacheConfig;
for (HostAndPort hostAndPort : clusterConfig.getNodes()) {
config.useClusterServers().addNodeAddress("redis://" + hostAndPort.getHost() + ":" + hostAndPort.getPort());
}
config.useClusterServers().setScanInterval(2000).setPassword(StringUtils.isNotBlank(clusterConfig.getPwd()) ? clusterConfig.getPwd() : null);
break;
case CLUSTER_POOL:
JedisClusterConnectSourceConfig clusterPoolConfig = (JedisClusterConnectSourceConfig) cacheConfig;
for (HostAndPort hostAndPort : clusterPoolConfig.getNodes()) {
config.useClusterServers().addNodeAddress("redis://" + hostAndPort.getHost() + ":" + hostAndPort.getPort());
}
config.useClusterServers().setScanInterval(2000).setPassword(StringUtils.isNotBlank(clusterPoolConfig.getPwd()) ? clusterPoolConfig.getPwd() : null);
break;
default:
return null;
}
return config;
}
use of com.lcache.config.BaseCacheConfig in project lcache by long172066912.
the class RedissonClientManager method getRedissonClient.
/**
* 获取Redisson客户端
*
* @param cacheConfigModel
* @param cacheConfig
* @return
*/
public static synchronized RedissonClient getRedissonClient(CacheConfigModel cacheConfigModel, BaseCacheConfig cacheConfig) {
RedissonClient redissonClient = null;
String key = CacheConfigUtils.modelToHashKey(cacheConfigModel);
if (null != redissonMap.get(key)) {
redissonClient = redissonMap.get(key);
if (!redissonClient.isShutdown()) {
return redissonClient;
}
}
Config config = getConfig(cacheConfigModel, cacheConfig);
if (null == config) {
CacheExceptionFactory.throwException("RedissonClientManager->getConfig error ! config is null !,cacheConfigModel:[{}],cacheConfig:[{}]", cacheConfigModel.toString() + JSON.toJSONString(cacheConfig));
}
// 设置线程数
config.setThreads(REDISSON_THREAD_NUM);
// 设置Netty线程数
config.setNettyThreads(REDISSON_THREAD_NUM);
redissonClient = Redisson.create(config);
redissonMap.put(key, redissonClient);
return redissonClient;
}
use of com.lcache.config.BaseCacheConfig 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