update m2pool redis 配置修复
This commit is contained in:
@@ -27,21 +27,13 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|||||||
* @Date 2024/6/13 09:58
|
* @Date 2024/6/13 09:58
|
||||||
* @Author dy
|
* @Author dy
|
||||||
*/
|
*/
|
||||||
@RefreshScope
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableCaching
|
@EnableCaching
|
||||||
public class RedisConfig extends CachingConfigurerSupport {
|
public class RedisConfig extends CachingConfigurerSupport {
|
||||||
|
|
||||||
@Value("${spring.redis.host}")
|
|
||||||
private String host;
|
|
||||||
@Value("${spring.redis.port}")
|
|
||||||
private int port;
|
|
||||||
@Value("${spring.redis.database:0}")
|
|
||||||
private int database = 0;
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@SuppressWarnings(value = { "unchecked", "rawtypes" })
|
@SuppressWarnings(value = { "unchecked", "rawtypes" })
|
||||||
public RedisTemplate<Object, Object> redisTemplate(@Qualifier("redisConnectionFactory0") RedisConnectionFactory connectionFactory)
|
public RedisTemplate<Object, Object> redisTemplate( RedisConnectionFactory connectionFactory)
|
||||||
{
|
{
|
||||||
RedisTemplate<Object, Object> template = new RedisTemplate<>();
|
RedisTemplate<Object, Object> template = new RedisTemplate<>();
|
||||||
template.setConnectionFactory(connectionFactory);
|
template.setConnectionFactory(connectionFactory);
|
||||||
@@ -65,46 +57,6 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||||||
template.afterPropertiesSet();
|
template.afterPropertiesSet();
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(name = "redisTemplate7")
|
|
||||||
public RedisTemplate<Object, Object> redisTemplate7(@Qualifier("redisConnectionFactory7") RedisConnectionFactory redisConnectionFactory0) {
|
|
||||||
RedisTemplate<Object, Object> template = new RedisTemplate<>();
|
|
||||||
template.setConnectionFactory(redisConnectionFactory0);
|
|
||||||
template.setKeySerializer(new StringRedisSerializer());
|
|
||||||
template.setValueSerializer(new StringRedisSerializer());
|
|
||||||
return template;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 7号 数据库 - >
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public RedisConnectionFactory redisConnectionFactory7() {
|
|
||||||
LettuceConnectionFactory factory = new LettuceConnectionFactory();
|
|
||||||
factory.setHostName(host);
|
|
||||||
factory.setPort(port);
|
|
||||||
factory.setDatabase(7);
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认 数据库
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
@Primary //添加@Primary默认使用的库
|
|
||||||
public RedisConnectionFactory redisConnectionFactory0() {
|
|
||||||
LettuceConnectionFactory factory = new LettuceConnectionFactory();
|
|
||||||
factory.setHostName(host);
|
|
||||||
factory.setPort(port);
|
|
||||||
factory.setDatabase(database);
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public DefaultRedisScript<Long> limitScript()
|
public DefaultRedisScript<Long> limitScript()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,10 +25,6 @@ public class RedisService {
|
|||||||
@Qualifier("redisTemplate")
|
@Qualifier("redisTemplate")
|
||||||
private RedisTemplate redisTemplate;
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
@Qualifier("redisTemplate7")
|
|
||||||
private RedisTemplate redisTemplate7;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存基本的对象,Integer、String、实体类等
|
* 缓存基本的对象,Integer、String、实体类等
|
||||||
@@ -56,10 +52,6 @@ public class RedisService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public <T> void setCacheObject7(final String key, final T value, final Long timeout, final TimeUnit timeUnit)
|
|
||||||
{
|
|
||||||
redisTemplate7.opsForValue().set(key, value, timeout, timeUnit);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置有效时间
|
* 设置有效时间
|
||||||
@@ -132,11 +124,6 @@ public class RedisService {
|
|||||||
return operation.get(key);
|
return operation.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T getCacheObject7(final String key)
|
|
||||||
{
|
|
||||||
ValueOperations<String, T> operation = redisTemplate7.opsForValue();
|
|
||||||
return operation.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所有数字类型转换为BigDecimal
|
* 所有数字类型转换为BigDecimal
|
||||||
|
|||||||
Reference in New Issue
Block a user