记得上下班打卡 | git大法好,push需谨慎

Commit 27847819 authored by anjiabin's avatar anjiabin

redis多数据源

parent 66cd5672
package com.liquidnet.common.cache.redis.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: AbstractRedisConfig
* @Package com.liquidnet.common.cache.redis.config
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/10/20 18:21
*/
@Slf4j
public abstract class AbstractRedisConfig {
public int defaultDb = 0;
public int totalDbs = 1;
public static Map<Integer, RedisTemplate<String, Object>> redisTemplateMap = new HashMap<>();
abstract String getHost();
abstract int getPort();
abstract String getPassword();
abstract int getMaxActive();
abstract int getMaxIdle();
abstract int getMinIdle();
abstract int getMaxWait();
abstract List<Integer> getDbs();
@PostConstruct
public void initRedisTemp() throws Exception {
log.info("###### START 初始化 Redis "+this.getClass().getSimpleName()+"连接池 START ######");
if(StringUtils.isEmpty(getHost())||getHost().equalsIgnoreCase("null")){
log.info("无配置,不需要初始化!");
return;
}
defaultDb = this.getDbs().get(0);
if(this.getDbs().size()==2&&this.getDbs().get(1)!=null){
totalDbs = this.getDbs().get(1);
log.info("init totalDbs : {}",totalDbs);
for (int i = 0;i < totalDbs; i++) {
log.info("###### 正在加载Redis-db-" + i+ " ######");
redisTemplateMap.put(i, getRedisTemplate(i));
}
}else{
log.info("init defaultDb : {}",defaultDb);
redisTemplateMap.put(defaultDb, getRedisTemplate(defaultDb));
}
log.info("###### END 初始化 Redis 连接池 END ######");
}
private RedisTemplate<String, Object> getRedisTemplate(int dbNo) {
return getRedisTemplate(getDbFactory(dbNo));
}
private LettuceConnectionFactory getDbFactory(int dbNo){
LettuceConnectionFactory factory = new LettuceConnectionFactory(getRedisConfig(dbNo), getClientConfig());
factory.afterPropertiesSet();//必须初始化实例
return factory;
}
private RedisStandaloneConfiguration getRedisConfig(int dbNo) {
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
config.setHostName(this.getHost());
config.setPort(this.getPort());
config.setPassword(this.getPassword());
config.setDatabase(dbNo);
return config;
}
private LettuceClientConfiguration getClientConfig() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(this.getMaxActive());
poolConfig.setMaxIdle(this.getMaxIdle());
poolConfig.setMinIdle(this.getMinIdle());
poolConfig.setMaxWaitMillis(this.getMaxWait());
return LettucePoolingClientConfiguration.builder().poolConfig(poolConfig).build();
}
private RedisTemplate<String, Object> getRedisTemplate(LettuceConnectionFactory factory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(factory);
setSerializer(redisTemplate);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
public RedisTemplate<String, Object> getRedisTemplateByDb(int db){
return redisTemplateMap.get(db);
}
@Bean
public RedisTemplate redisTemplate() {
LettuceConnectionFactory factory = null;
if(totalDbs==1){
factory = getDbFactory(defaultDb);
}else{
factory = getDbFactory(totalDbs-1);
}
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(factory);
setSerializer(redisTemplate);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
@Bean
public StringRedisTemplate stringRedisTemplate() {
LettuceConnectionFactory factory = null;
if(totalDbs==1){
factory = getDbFactory(defaultDb);
}else{
factory = getDbFactory(totalDbs-1);
}
StringRedisTemplate redisTemplate = new StringRedisTemplate();
redisTemplate.setConnectionFactory(factory);
return redisTemplate;
}
private void setSerializer(RedisTemplate<String, Object> template) {
Jackson2JsonRedisSerializer j2jrs = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
om.registerModule(new JavaTimeModule());
om.activateDefaultTyping(om.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL);
j2jrs.setObjectMapper(om);
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
// key采用String的序列化方式
template.setKeySerializer(stringRedisSerializer);
// hash的key也采用String的序列化方式
template.setHashKeySerializer(stringRedisSerializer);
// value序列化方式采用jackson
template.setValueSerializer(j2jrs);
// hash的value序列化方式采用jackson
template.setHashValueSerializer(j2jrs);
template.afterPropertiesSet();
}
}
package com.liquidnet.common.cache.redis.config;//package com.liquidnet.common.cache.redis.config; package com.liquidnet.common.cache.redis.config;//package com.liquidnet.common.cache.redis.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
...@@ -36,137 +18,49 @@ import java.util.Map; ...@@ -36,137 +18,49 @@ import java.util.Map;
*/ */
@Slf4j @Slf4j
@Configuration @Configuration
public class RedisConfig { public class RedisConfig extends AbstractRedisConfig{
@Value("${spring.redis.host}") @Value("${spring.redis.host:null}")
private String host; private String host;
@Value("${spring.redis.port}") @Value("${spring.redis.port:-1}")
private int port; private int port;
@Value("${spring.redis.password}") @Value("${spring.redis.password:null}")
private String password; private String password;
@Value("${spring.redis.lettuce.pool.max-active}") @Value("${spring.redis.lettuce.pool.max-active:-1}")
private int maxActive; private int maxActive;
@Value("${spring.redis.lettuce.pool.max-idle}") @Value("${spring.redis.lettuce.pool.max-idle:-1}")
private int maxIdle; private int maxIdle;
@Value("${spring.redis.lettuce.pool.min-idle}") @Value("${spring.redis.lettuce.pool.min-idle:-1}")
private int minIdle; private int minIdle;
@Value("${spring.redis.lettuce.pool.max-wait}") @Value("${spring.redis.lettuce.pool.max-wait:-1}")
private int maxWait; private int maxWait;
public static int defaultDb = 0; @Value("${spring.redis.dbs:${spring.redis.database:-1}}")
public static int totalDbs = 1;
@Value("${spring.redis.dbs:${spring.redis.database}}")
private List<Integer> dbs; private List<Integer> dbs;
String getHost(){
public static Map<Integer, RedisTemplate<String, Object>> redisTemplateMap = new HashMap<>(); return this.host;
@PostConstruct
public void initRedisTemp() throws Exception {
log.info("###### START 初始化 Redis 连接池 START ######");
defaultDb = dbs.get(0);
if(dbs.size()==2&&dbs.get(1)!=null){
totalDbs = dbs.get(1);
log.info("init totalDbs : {}",totalDbs);
for (int i = 0;i < totalDbs; i++) {
log.info("###### 正在加载Redis-db-" + i+ " ######");
redisTemplateMap.put(i, getRedisTemplate(i));
}
}else{
log.info("init defaultDb : {}",defaultDb);
redisTemplateMap.put(defaultDb, getRedisTemplate(defaultDb));
}
log.info("###### END 初始化 Redis 连接池 END ######");
} }
private RedisTemplate<String, Object> getRedisTemplate(int dbNo) { int getPort(){
return getRedisTemplate(getDbFactory(dbNo)); return this.port;
} }
String getPassword(){
private LettuceConnectionFactory getDbFactory(int dbNo){ return this.password;
LettuceConnectionFactory factory = new LettuceConnectionFactory(getRedisConfig(dbNo), getClientConfig());
factory.afterPropertiesSet();//必须初始化实例
return factory;
} }
int getMaxActive(){
private RedisStandaloneConfiguration getRedisConfig(int dbNo) { return this.maxActive;
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
config.setHostName(host);
config.setPort(port);
config.setPassword(password);
config.setDatabase(dbNo);
return config;
} }
int getMaxIdle(){
private LettuceClientConfiguration getClientConfig() { return this.maxIdle;
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(maxActive);
poolConfig.setMaxIdle(maxIdle);
poolConfig.setMinIdle(minIdle);
poolConfig.setMaxWaitMillis(maxWait);
return LettucePoolingClientConfiguration.builder().poolConfig(poolConfig).build();
} }
int getMinIdle(){
private RedisTemplate<String, Object> getRedisTemplate(LettuceConnectionFactory factory) { return this.minIdle;
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(factory);
setSerializer(redisTemplate);
redisTemplate.afterPropertiesSet();
return redisTemplate;
} }
int getMaxWait(){
public RedisTemplate<String, Object> getRedisTemplateByDb(int db){ return this.maxWait;
return redisTemplateMap.get(db);
}
@Bean
public RedisTemplate redisTemplate() {
LettuceConnectionFactory factory = null;
if(totalDbs==1){
factory = getDbFactory(defaultDb);
}else{
factory = getDbFactory(totalDbs-1);
}
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(factory);
setSerializer(redisTemplate);
redisTemplate.afterPropertiesSet();
return redisTemplate;
} }
List<Integer> getDbs(){
@Bean return this.dbs;
public StringRedisTemplate stringRedisTemplate() {
LettuceConnectionFactory factory = null;
if(totalDbs==1){
factory = getDbFactory(defaultDb);
}else{
factory = getDbFactory(totalDbs-1);
}
StringRedisTemplate redisTemplate = new StringRedisTemplate();
redisTemplate.setConnectionFactory(factory);
return redisTemplate;
}
private void setSerializer(RedisTemplate<String, Object> template) {
Jackson2JsonRedisSerializer j2jrs = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
om.registerModule(new JavaTimeModule());
om.activateDefaultTyping(om.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL);
j2jrs.setObjectMapper(om);
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
// key采用String的序列化方式
template.setKeySerializer(stringRedisSerializer);
// hash的key也采用String的序列化方式
template.setHashKeySerializer(stringRedisSerializer);
// value序列化方式采用jackson
template.setValueSerializer(j2jrs);
// hash的value序列化方式采用jackson
template.setHashValueSerializer(j2jrs);
template.afterPropertiesSet();
} }
} }
\ No newline at end of file
package com.liquidnet.common.cache.redis.config;//package com.liquidnet.common.cache.redis.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import java.util.List;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: RedisConfig
* @Package com.liquidnet.common.cache.redis.config
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/8/10 16:28
*/
@Slf4j
@Configuration
public class RedisDb2Config extends AbstractRedisConfig{
@Value("${spring.redis.db2.host:null}")
private String host;
@Value("${spring.redis.db2.port:-1}")
private int port;
@Value("${spring.redis.db2.password:null}")
private String password;
@Value("${spring.redis.db2.lettuce.pool.max-active:-1}")
private int maxActive;
@Value("${spring.redis.db2.lettuce.pool.max-idle:-1}")
private int maxIdle;
@Value("${spring.redis.db2.lettuce.pool.min-idle:-1}")
private int minIdle;
@Value("${spring.redis.db2.lettuce.pool.max-wait:-1}")
private int maxWait;
@Value("${spring.redis.db2.dbs:${spring.redis.db2.database:-1}}")
private List<Integer> dbs;
public RedisDb2Config(){
}
String getHost(){
return this.host;
}
int getPort(){
return this.port;
}
String getPassword(){
return this.password;
}
int getMaxActive(){
return this.maxActive;
}
int getMaxIdle(){
return this.maxIdle;
}
int getMinIdle(){
return this.minIdle;
}
int getMaxWait(){
return this.maxWait;
}
List<Integer> getDbs(){
return this.dbs;
}
}
\ No newline at end of file
package com.liquidnet.common.cache.redis.config;//package com.liquidnet.common.cache.redis.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import java.util.List;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: RedisConfig
* @Package com.liquidnet.common.cache.redis.config
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/8/10 16:28
*/
@Slf4j
@Configuration
public class RedisDb3Config extends AbstractRedisConfig{
@Value("${spring.redis.db3.host:null}")
private String host;
@Value("${spring.redis.db3.port:-1}")
private int port;
@Value("${spring.redis.db3.password:null}")
private String password;
@Value("${spring.redis.db3.lettuce.pool.max-active:-1}")
private int maxActive;
@Value("${spring.redis.db3.lettuce.pool.max-idle:-1}")
private int maxIdle;
@Value("${spring.redis.db3.lettuce.pool.min-idle:-1}")
private int minIdle;
@Value("${spring.redis.db3.lettuce.pool.max-wait:-1}")
private int maxWait;
@Value("${spring.redis.db3.dbs:${spring.redis.db3.database:-1}}")
private List<Integer> dbs;
String getHost(){
return this.host;
}
int getPort(){
return this.port;
}
String getPassword(){
return this.password;
}
int getMaxActive(){
return this.maxActive;
}
int getMaxIdle(){
return this.maxIdle;
}
int getMinIdle(){
return this.minIdle;
}
int getMaxWait(){
return this.maxWait;
}
List<Integer> getDbs(){
return this.dbs;
}
}
\ No newline at end of file
package com.liquidnet.common.cache.redis.config;//package com.liquidnet.common.cache.redis.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import java.util.List;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: RedisConfig
* @Package com.liquidnet.common.cache.redis.config
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/8/10 16:28
*/
@Slf4j
@Configuration
public class RedisDb4Config extends AbstractRedisConfig {
@Value("${spring.redis.db4.host:null}")
private String host;
@Value("${spring.redis.db4.port:-1}")
private int port;
@Value("${spring.redis.db4.password:null}")
private String password;
@Value("${spring.redis.db4.lettuce.pool.max-active:-1}")
private int maxActive;
@Value("${spring.redis.db4.lettuce.pool.max-idle:-1}")
private int maxIdle;
@Value("${spring.redis.db4.lettuce.pool.min-idle:-1}")
private int minIdle;
@Value("${spring.redis.db4.lettuce.pool.max-wait:-1}")
private int maxWait;
@Value("${spring.redis.db4.dbs:${spring.redis.db4.database:-1}}")
private List<Integer> dbs;
String getHost(){
return this.host;
}
int getPort(){
return this.port;
}
String getPassword(){
return this.password;
}
int getMaxActive(){
return this.maxActive;
}
int getMaxIdle(){
return this.maxIdle;
}
int getMinIdle(){
return this.minIdle;
}
int getMaxWait(){
return this.maxWait;
}
List<Integer> getDbs(){
return this.dbs;
}
}
\ No newline at end of file
package com.liquidnet.common.cache.redis.config;//package com.liquidnet.common.cache.redis.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import java.util.List;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: RedisConfig
* @Package com.liquidnet.common.cache.redis.config
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/8/10 16:28
*/
@Slf4j
@Configuration
public class RedisDb5Config extends AbstractRedisConfig {
@Value("${spring.redis.db5.host:null}")
private String host;
@Value("${spring.redis.db5.port:-1}")
private int port;
@Value("${spring.redis.db5.password:null}")
private String password;
@Value("${spring.redis.db5.lettuce.pool.max-active:-1}")
private int maxActive;
@Value("${spring.redis.db5.lettuce.pool.max-idle:-1}")
private int maxIdle;
@Value("${spring.redis.db5.lettuce.pool.min-idle:-1}")
private int minIdle;
@Value("${spring.redis.db5.lettuce.pool.max-wait:-1}")
private int maxWait;
@Value("${spring.redis.db5.dbs:${spring.redis.db5.database:-1}}")
private List<Integer> dbs;
String getHost(){
return this.host;
}
int getPort(){
return this.port;
}
String getPassword(){
return this.password;
}
int getMaxActive(){
return this.maxActive;
}
int getMaxIdle(){
return this.maxIdle;
}
int getMinIdle(){
return this.minIdle;
}
int getMaxWait(){
return this.maxWait;
}
List<Integer> getDbs(){
return this.dbs;
}
}
\ No newline at end of file
...@@ -14,10 +14,10 @@ import lombok.extern.slf4j.Slf4j; ...@@ -14,10 +14,10 @@ import lombok.extern.slf4j.Slf4j;
*/ */
@Slf4j @Slf4j
public class MathUtil { public class MathUtil {
public static int getIndex(String key){ public static int getIndex(String key,int defaultDb,int totalDbs){
log.debug("MathUtil.getIndex key:{} hashcode:{}",key,key.hashCode()); log.debug("MathUtil.getIndex key:{} hashcode:{}",key,key.hashCode());
int defaultDb = RedisConfig.defaultDb; // int defaultDb = RedisConfig.defaultDb;
int totalDbs = RedisConfig.totalDbs; // int totalDbs = RedisConfig.totalDbs;
if(totalDbs==1){ if(totalDbs==1){
log.info("only one db : {} ",defaultDb); log.info("only one db : {} ",defaultDb);
return defaultDb; return defaultDb;
...@@ -39,6 +39,8 @@ public class MathUtil { ...@@ -39,6 +39,8 @@ public class MathUtil {
public static void main(String[] args) { public static void main(String[] args) {
RedisConfig redisConfig = new RedisConfig(); RedisConfig redisConfig = new RedisConfig();
redisConfig.getRedisTemplateByDb(MathUtil.getIndex("1")); log.info("redisConfig.defaultDb===",redisConfig.defaultDb);
log.info("redisConfig.totalDbs===",redisConfig.totalDbs);
redisConfig.getRedisTemplateByDb(MathUtil.getIndex("1",redisConfig.defaultDb,redisConfig.totalDbs));
} }
} }
package com.liquidnet.common.cache.redis.util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author AnJiabin <anjiabin@zhengzai.tv>
* @version V1.0
* @Description: TODO
* @class: PlatformRedisUtil
* @Package com.liquidnet.common.cache.redis.util
* @Copyright: LightNet @ Copyright (c) 2021
* @date 2021/10/20 18:13
*/
@Component
public class RedisDataSourceUtil {
@Autowired
private RedisUtil redisUtil;
@Autowired
private RedisDb2Util redisDb2Util;
@Autowired
private RedisDb3Util redisDb3Util;
@Autowired
private RedisDb4Util redisDb4Util;
@Autowired
private RedisDb5Util redisDb5Util;
public AbstractRedisUtil getRedisDb1Util(){
return this.redisUtil;
}
public AbstractRedisUtil getRedisDb2Util(){
return this.redisDb2Util;
}
public AbstractRedisUtil getRedisDb3Util(){
return this.redisDb3Util;
}
public AbstractRedisUtil getRedisDb4Util(){
return this.redisDb4Util;
}
public AbstractRedisUtil getRedisDb5Util(){
return this.redisDb5Util;
}
}
package com.liquidnet.common.cache.redis.util;
import com.liquidnet.common.cache.redis.config.AbstractRedisConfig;
import com.liquidnet.common.cache.redis.config.RedisDb2Config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author AnJiabin <jiabin.an@lightnet.io>
* @version V1.0
* @Description: Redis工具类
* @class: RedisUtil
* @Package com.liquidnet.stellar.utils
* @Copyright: LightNet @ Copyright (c) 2020
* @date 2020/8/26 13:11
*/
@Slf4j
@Component("redisDb2Util")
public final class RedisDb2Util extends AbstractRedisUtil{
@Autowired
private RedisDb2Config redisConfig;
@Override
public int getDbs() {
log.info("redisDb2Config.totalDbs===",redisConfig.totalDbs);
return redisConfig.totalDbs;
}
@Override
AbstractRedisConfig getRedisConfig() {
return this.redisConfig;
}
}
package com.liquidnet.common.cache.redis.util;
import com.liquidnet.common.cache.redis.config.AbstractRedisConfig;
import com.liquidnet.common.cache.redis.config.RedisDb3Config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author AnJiabin <jiabin.an@lightnet.io>
* @version V1.0
* @Description: Redis工具类
* @class: RedisUtil
* @Package com.liquidnet.stellar.utils
* @Copyright: LightNet @ Copyright (c) 2020
* @date 2020/8/26 13:11
*/
@Slf4j
@Component("redisDb3Util")
public final class RedisDb3Util extends AbstractRedisUtil{
@Autowired
private RedisDb3Config redisConfig;
@Override
public int getDbs() {
log.info("redisDb3Config.totalDbs===",redisConfig.totalDbs);
return redisConfig.totalDbs;
}
@Override
AbstractRedisConfig getRedisConfig() {
return this.redisConfig;
}
}
package com.liquidnet.common.cache.redis.util;
import com.liquidnet.common.cache.redis.config.AbstractRedisConfig;
import com.liquidnet.common.cache.redis.config.RedisDb4Config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author AnJiabin <jiabin.an@lightnet.io>
* @version V1.0
* @Description: Redis工具类
* @class: RedisUtil
* @Package com.liquidnet.stellar.utils
* @Copyright: LightNet @ Copyright (c) 2020
* @date 2020/8/26 13:11
*/
@Slf4j
@Component("redisDb4Util")
public final class RedisDb4Util extends AbstractRedisUtil{
@Autowired
private RedisDb4Config redisConfig;
@Override
public int getDbs() {
log.info("redisDb4Config.totalDbs===",redisConfig.totalDbs);
return redisConfig.totalDbs;
}
@Override
AbstractRedisConfig getRedisConfig() {
return this.redisConfig;
}
}
package com.liquidnet.common.cache.redis.util;
import com.liquidnet.common.cache.redis.config.AbstractRedisConfig;
import com.liquidnet.common.cache.redis.config.RedisDb5Config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author AnJiabin <jiabin.an@lightnet.io>
* @version V1.0
* @Description: Redis工具类
* @class: RedisUtil
* @Package com.liquidnet.stellar.utils
* @Copyright: LightNet @ Copyright (c) 2020
* @date 2020/8/26 13:11
*/
@Slf4j
@Component("redisDb5Util")
public final class RedisDb5Util extends AbstractRedisUtil{
@Autowired
private RedisDb5Config redisConfig;
@Override
public int getDbs() {
log.info("redisDb5Config.totalDbs===",redisConfig.totalDbs);
return redisConfig.totalDbs;
}
@Override
AbstractRedisConfig getRedisConfig() {
return this.redisConfig;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment