com.luues.redis.config.JedisConfig Maven / Gradle / Ivy
package com.luues.redis.config;
import cn.luues.tool.core.util.ClassUtil;
import cn.luues.tool.json.JsonUtils;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.luues.core.config.CoreProperties;
import com.luues.core.core.SpringContextHolder;
import com.luues.redis.annotation.EnableRedisCache;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.lang.reflect.Method;
import java.util.Set;
@Data
@Slf4j(topic = "c.l.r.c.j")
public class JedisConfig {
private static JedisConfig jedisConfig = null;
public static JedisConfig getJedisConfig(){
return jedisConfig;
}
private JedisConfig(){}
private boolean cusCache;
static {
synchronized (JedisConfig.class){
if(null == jedisConfig){
CoreProperties coreProperties = SpringContextHolder.getBean(CoreProperties.class);
Set> set = ClassUtil.scanPackageByAnnotation(coreProperties.getPackageName(), EnableRedisCache.class);
if(set.size() == 1){
EnableRedisCache enableRedisCache = set.iterator().next().getAnnotation(EnableRedisCache.class);
jedisConfig = new JedisConfig();
jedisConfig.setCusCache(enableRedisCache.cusCache());
}else {
Method[] methods = EnableRedisCache.class.getDeclaredMethods();
ObjectNode objectNode = JsonUtils.createObjectNode();
for(Method method : methods){
objectNode.put(method.getName(), (boolean)method.getDefaultValue());
}
jedisConfig = JsonUtils.parse(objectNode.toString(), JedisConfig.class);
}
log.info("@EnableRedisCache is : {}", JsonUtils.toJson(jedisConfig));
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy