亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

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
佛坪县| 霞浦县| 石城县| 嘉黎县| 无锡市| 枣庄市| 黄骅市| 资阳市| 土默特左旗| 绵竹市| 黄大仙区| 全州县| 岐山县| 溧阳市| 卫辉市| 堆龙德庆县| 乌拉特中旗| 井冈山市| 揭阳市| 潮州市| 平远县| 阳信县| 上栗县| 磐安县| 突泉县| 合阳县| 梁平县| 于都县| 维西| 彭州市| 富阳市| 油尖旺区| 临桂县| 多伦县| 盐池县| 华安县| 天祝| 安陆市| 专栏| 高要市| 沙雅县|