redis宕机如何保证业务正常

redis宕机如何保证业务正常

redis宕机可通过实现Redis缓存切面来保证业务正常,示例代码:

package com.raymon.hcp.security.aspect;

import com.raymon.hcp.security.annotation.CacheException;

import org.aspectj.lang.ProceedingJoinPoint;

import org.aspectj.lang.Signature;

import org.aspectj.lang.annotation.Around;

import org.aspectj.lang.annotation.Aspect;

import org.aspectj.lang.annotation.Pointcut;

import org.aspectj.lang.reflect.MethodSignature;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.core.annotation.Order;

import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**

* Redis缓存切面,防止Redis宕机影响正常业务逻辑

* Created by zhanglei on 2020/3/17.

*/

@Aspect

@Component

@Order(2)

public class RedisCacheAspect {

private static Logger LOGGER = LoggerFactory.getLogger(RedisCacheAspect.class);

@Pointcut("execution(public * com.raymon.hcp.portal.service.*CacheService.*(..)) || execution(public * com.raymon.hcp.service.*CacheService.*(..))")

public void cacheAspect() {

}

@Around("cacheAspect()")

public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {

Signature signature = joinPoint.getSignature();

MethodSignature methodSignature = (MethodSignature) signature;

Method method = methodSignature.getMethod();

Object result = null;

try {

result = joinPoint.proceed();

} catch (Throwable throwable) {

//有CacheException注解的方法需要抛出异常

if (method.isAnnotationPresent(CacheException.class)) {

throw throwable;

} else {

LOGGER.error(throwable.getMessage());

}

}

return result;

}

}

我们的服务
专业提供中小企业网站建设.公司网站建设.外贸网站建设.营销型网站建设,响应式网站建设,商城网站定制,手机网站,微信小程序定制.php应用开发服务,公司成立于2014年,8年专注网站建设,秉承“以客户为根本,以科技为核心,以市场为导向”的经营理念;服务电话13714666846(微信同号)

声明:本站所有作品(图文、音视频)均由用户自行上传分享,或互联网相关知识整合,仅供网友学习交流,若您的权利被侵害,请联系 管理员 删除。

本文链接:http://news.ew35.com/