Py学习  »  Redis

如何创建redis条件bean?

Ravirajsinh Vaghela • 4 年前 • 462 次点击  

我需要创造 重新发现 JAVA配置中的bean。

如果找不到redis配置(redis server info),则使用空缓存创建默认的redis bean。

你能建议一下吗?

提前谢谢。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/40078
 
462 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Oliver Nybroe Muhammad Inshal
Reply   •   1 楼
Oliver Nybroe Muhammad Inshal    5 年前

如果redis服务器没有运行,则需要实现一个缓存错误处理程序,如果数据没有缓存,该处理程序将重定向到要调用的原始方法。下面的错误处理程序应该做到这一点:

@Component
public class RedisCacheErrorHandler implements CacheErrorHandler {

    private final Logger log = LoggerFactory.getLogger(getClass());

    @Override
    public void handleCacheGetError(RuntimeException exception, Cache cache, Object key) {
    log.info("Unable to get from cache " + cache.getName() + " : " + exception.getMessage());
    }

    @Override
    public void handleCachePutError(RuntimeException exception, Cache cache, Object key, Object value) {
        log.info("Unable to put into cache " + cache.getName() + " : " + exception.getMessage());
    }

    @Override
    public void handleCacheEvictError(RuntimeException exception, Cache cache, Object key) {
        log.info("Unable to evict from cache " + cache.getName() + " : " + exception.getMessage());
    }

    @Override
    public void handleCacheClearError(RuntimeException exception, Cache cache) {
        log.info("Unable to clean cache " + cache.getName() + " : " + exception.getMessage());
    }
}