Search in sources :

Example 1 with RedisNoScriptException

use of io.lettuce.core.RedisNoScriptException 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);
        }
    }
}
Also used : BaseCacheConfig(com.lcache.config.BaseCacheConfig) LettuceConnectResource(com.lcache.extend.handle.redis.lettuce.connect.LettuceConnectResource) RedisNoScriptException(io.lettuce.core.RedisNoScriptException) RedisNoScriptException(io.lettuce.core.RedisNoScriptException)

Aggregations

BaseCacheConfig (com.lcache.config.BaseCacheConfig)1 LettuceConnectResource (com.lcache.extend.handle.redis.lettuce.connect.LettuceConnectResource)1 RedisNoScriptException (io.lettuce.core.RedisNoScriptException)1