Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 使用spring boot在多次超时时禁用redis_Spring Boot_Redis - Fatal编程技术网

Spring boot 使用spring boot在多次超时时禁用redis

Spring boot 使用spring boot在多次超时时禁用redis,spring-boot,redis,Spring Boot,Redis,我在AWS EC2中部署了一个应用程序,有时(很少),我无法在redis中连接和执行任何命令,我正在调查这个问题的根本原因 我正在使用SpringBoot+Redis(Elasticcache) 我正在使用包装器捕获任何异常以继续请求过程 我的包装纸: class RedisCacheWrapper implements Cache { private final Cache delegate; public RedisCacheWrapper(Cache redisCache) {

我在AWS EC2中部署了一个应用程序,有时(很少),我无法在redis中连接和执行任何命令,我正在调查这个问题的根本原因

我正在使用SpringBoot+Redis(Elasticcache)

我正在使用包装器捕获任何异常以继续请求过程

我的包装纸:

class RedisCacheWrapper implements Cache {

private final Cache delegate;

public RedisCacheWrapper(Cache redisCache) {
    Assert.notNull(redisCache, "delegate cache must not be null");
    this.delegate = redisCache;
}

@Override
public String getName() {
    try {
        return delegate.getName();
    } catch (Exception e) {
        return handleException(e);
    }
}

@Override
public Object getNativeCache() {
    try {
        return delegate.getNativeCache();
    } catch (Exception e) {
        return handleException(e);
    }
}

@Override
public ValueWrapper get(Object key) {
    try {
        return delegate.get(key);
    } catch (Exception e) {
        return handleException(e);
    }
}

@Override
public <T> T get(Object o, Class<T> type) {
    try {
        return delegate.get(o, type);
    } catch (Exception e) {
        return handleException(e);
    }
}

@Override
public <T> T get(Object o, Callable<T> callable) {
    try {
        return delegate.get(o, callable);
    } catch (Exception e) {
        return handleException(e);
    }
}

@Override
public void put(Object key, Object value) {
    try {
        delegate.put(key, value);
    } catch (Exception e) {
        handleException(e);
    }
}

@Override
public ValueWrapper putIfAbsent(Object o, Object o1) {
    try {
        return delegate.putIfAbsent(o, o1);
    } catch (Exception e) {
        return handleException(e);
    }
}

@Override
public void evict(Object o) {
    try {
        delegate.evict(o);
    } catch (Exception e) {
        handleException(e);
    }
}

@Override
public void clear() {
    try {
        delegate.clear();
    } catch (Exception e) {
        handleException(e);
    }
}

private <T> T handleException(Exception e) {
    log.error("handleException", e);
    return null;
}}
我的疑问是: 有一个很好的方法来禁用缓存临时(不进行任何部署),而redis不好吗?例如:使用断路器

我认为这样做:

    @Cacheable()
    myMethodCached(){
       myRealMethod();
    }

    myRealMethod(){}
将“myMethodCached”放在HystrixCommand中,若超时被抛出,则执行回退方法而不使用redis

这种方法的问题是,我需要为所有使用缓存的方法创建一个“回退”,我希望全局“禁用”(将跳过所有缓存)

有没有一个好的解决方案可以“禁用”redis一段时间

    @Cacheable()
    myMethodCached(){
       myRealMethod();
    }

    myRealMethod(){}