2022-03-08 18:26:38 +08:00
|
|
|
package io.dataease.config;
|
|
|
|
|
|
|
|
|
|
|
|
import io.dataease.commons.condition.RedisStatusCondition;
|
2022-04-13 18:30:31 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2022-03-08 18:26:38 +08:00
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Conditional;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
2022-04-13 18:30:31 +08:00
|
|
|
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
2022-03-08 18:26:38 +08:00
|
|
|
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
|
|
|
|
|
|
|
|
2022-04-13 18:30:31 +08:00
|
|
|
@Conditional({RedisStatusCondition.class})
|
2022-03-08 18:26:38 +08:00
|
|
|
@Configuration
|
|
|
|
public class RedisConfig {
|
|
|
|
|
2022-04-13 18:30:31 +08:00
|
|
|
@Autowired
|
|
|
|
private RedisConnectionFactory redisConnectionFactory;
|
|
|
|
|
|
|
|
|
2022-03-08 18:26:38 +08:00
|
|
|
@Bean
|
|
|
|
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory factory) {
|
|
|
|
RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
|
|
|
|
redisTemplate.setConnectionFactory(factory);
|
|
|
|
Jackson2JsonRedisSerializer<Object> serializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
|
|
|
|
redisTemplate.setDefaultSerializer(serializer);
|
|
|
|
return redisTemplate;
|
|
|
|
}
|
|
|
|
|
2022-04-13 18:30:31 +08:00
|
|
|
@Bean
|
|
|
|
public RedisMessageListenerContainer redisContainer() {
|
|
|
|
final RedisMessageListenerContainer container = new RedisMessageListenerContainer();
|
|
|
|
container.setConnectionFactory(redisConnectionFactory);
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2022-03-08 18:26:38 +08:00
|
|
|
}
|