標籤:efault res 串連數 sse contex turn led mapper int
package com.qmtt.config;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.data.redis.connection.Message;import org.springframework.data.redis.connection.MessageListener;import org.springframework.data.redis.connection.RedisConnectionFactory;import org.springframework.data.redis.core.RedisTemplate;import org.springframework.data.redis.core.StringRedisTemplate;import org.springframework.data.redis.listener.ChannelTopic;import org.springframework.data.redis.listener.RedisMessageListenerContainer;import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;import com.fasterxml.jackson.annotation.JsonAutoDetect;import com.fasterxml.jackson.annotation.PropertyAccessor;import com.fasterxml.jackson.databind.ObjectMapper;@Configurationpublic class RedisConfig { @Bean public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) { StringRedisTemplate template = new StringRedisTemplate(factory); setSerializer(template);// 設定序列化工具 template.afterPropertiesSet(); return template; } private void setSerializer(StringRedisTemplate template) { @SuppressWarnings({ "rawtypes", "unchecked" }) Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); ObjectMapper om = new ObjectMapper(); om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); jackson2JsonRedisSerializer.setObjectMapper(om); template.setValueSerializer(jackson2JsonRedisSerializer); } // 訂閱pubsub:queue @Bean RedisMessageListenerContainer redisContainer(RedisConnectionFactory factory) { final RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(factory); MessageListenerAdapter listener = new MessageListenerAdapter(new RedisMessageListener()); container.addMessageListener(listener, new ChannelTopic("pubsub:queue")); return container; } public class RedisMessageListener implements MessageListener { @Override public void onMessage(final Message message, final byte[] pattern) { System.out.println("Message received: " + message.toString()); } }}
#redis相關配置# Redis資料庫索引(預設為0)spring.redis.database=0# Redis伺服器位址spring.redis.host=127.0.0.1# Redis伺服器串連連接埠spring.redis.port=6379# Redis伺服器串連密碼(預設為空白)spring.redis.password=111# 串連池最大串連數(使用負值表示沒有限制)spring.redis.pool.max-active=100# 串連池最大阻塞等待時間(使用負值表示沒有限制)spring.redis.pool.max-wait=-1# 串連池中的最大空閑串連spring.redis.pool.max-idle=20# 串連池中的最小空閑串連spring.redis.pool.min-idle=10# 連線逾時時間(毫秒)spring.redis.timeout=0
spring boot整合redis