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

溫馨提示×

redis宕機如何保證業務正常

小新
644
2021-01-16 09:07: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
湖北省| 新密市| 河南省| 宣化县| 玛多县| 隆回县| 松原市| 石柱| 尼木县| 元朗区| 南岸区| 靖江市| 平凉市| 如东县| 隆昌县| 棋牌| 湄潭县| 枣强县| 旌德县| 平顶山市| 松阳县| 满城县| 湖南省| 即墨市| 南华县| 晋城| 根河市| 新干县| 郑州市| 安平县| 呼图壁县| 龙陵县| 雷州市| 巴林右旗| 山西省| 合江县| 香格里拉县| 柳州市| 达拉特旗| 江安县| 迁西县|