Commit 633c90d3 authored by Quxl's avatar Quxl

增加Redis配置,用于数据会话缓存

Change-Id: I292f4875f2548cdd8297a5c626fba6f0c60bbbb3
parent 06184336
package com.egolm.shop.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<String, ?> getRedisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, ?> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
Jackson2JsonRedisSerializer<?> valueSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
valueSerializer.setObjectMapper(mapper);
template.setValueSerializer(valueSerializer);
template.setKeySerializer(new StringRedisSerializer());
template.afterPropertiesSet();
return template;
}
}
...@@ -19,4 +19,15 @@ spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver ...@@ -19,4 +19,15 @@ spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.testWhileIdle=true spring.datasource.testWhileIdle=true
spring.datasource.validationQueryTimeout=5 spring.datasource.validationQueryTimeout=5
spring.datasource.validationQuery=SELECT 1 spring.datasource.validationQuery=SELECT 1
spring.datasource.timeBetweenEvictionRunsMillis=3600000 spring.datasource.timeBetweenEvictionRunsMillis=3600000
\ No newline at end of file
spring.redis.database=0
spring.redis.host=ossip.cn
spring.redis.port=6379
spring.redis.password=@8UiMqvDtNgv
spring.redis.timeout=2000
spring.redis.pool.max-active=20
spring.redis.pool.max-wait=2000
spring.redis.pool.max-idle=5
spring.redis.pool.min-idle=0
\ No newline at end of file
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