redis配置类
/**
* Redis配置
*
* @author suxii
* @version 1.0.0
*/
@Configuration(proxyBeanMethods = false)
public class RedisConfig implements BeanClassLoaderAware {
private ClassLoader classLoader;
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.setKeySerializer(RedisSerializer.string());
redisTemplate.setHashKeySerializer(RedisSerializer.string());
RedisSerializer<Object> objectRedisSerializer = RedisSerializer.java(classLoader);
redisTemplate.setValueSerializer(objectRedisSerializer);
redisTemplate.setHashValueSerializer(objectRedisSerializer);
return redisTemplate;
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.classLoader=classLoader;
}
}
yml配置文件
# Redis 相关配置
redis:
# Redis 服务器主机地址
host: localhost
# Redis 服务器端口号
port: 6379
# Redis 认证密码(如果需要)
# password:
# 连接 Redis 服务器超时时间(单位:毫秒)
timeout: 3000
# 使用 Jedis 客户端时的连接池相关配置
jedis:
pool:
# 连接池最大活动连接数
max-active: 8
# 连接池最大等待时间(单位:毫秒),负值表示无限等待
max-wait: -1
# 连接池最大空闲连接数
max-idle: 8
# 连接池最小空闲连接数
min-idle: 0
评论 (0)