中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

redis宕機如何保證業務正常

小新
168
2021-01-16 19:35:04
欄目: 云計算

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;

}

}

0
青浦区| 林口县| 崇礼县| 通化县| 盐山县| 九寨沟县| 闵行区| 绥滨县| 黄平县| 廊坊市| 龙山县| 日喀则市| 繁昌县| 赤水市| 集贤县| 云安县| 奉节县| 黔西| 沙田区| 蓝田县| 斗六市| 夏河县| 乌鲁木齐县| 石棉县| 眉山市| 新化县| 临沭县| 和平区| 堆龙德庆县| 丰原市| 安顺市| 东平县| 巴彦县| 高陵县| 同江市| 辛集市| 监利县| 花莲市| 临夏县| 腾冲县| 定边县|