From eca1e05aeed3c51cce36bbce80c71bc3cbcea87d Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期五, 12 十一月 2021 14:40:39 +0800 Subject: [PATCH] 维护目录订阅消息与接口 --- src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java | 42 ++++++++++++++++++++++++++++++++++++++---- 1 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java index 3448a2f..dcb0e81 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java @@ -1,5 +1,7 @@ package com.genersoft.iot.vmp.conf; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -10,15 +12,48 @@ import com.alibaba.fastjson.parser.ParserConfig; import com.genersoft.iot.vmp.utils.redis.FastJsonRedisSerializer; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; /** - * @Description:Redis涓棿浠堕厤缃被锛屼娇鐢╯pring-data-redis闆嗘垚锛岃嚜鍔ㄤ粠application.yml涓姞杞絩edis閰嶇疆 - * @author: songww + * @description:Redis涓棿浠堕厤缃被锛屼娇鐢╯pring-data-redis闆嗘垚锛岃嚜鍔ㄤ粠application.yml涓姞杞絩edis閰嶇疆 + * @author: swwheihei * @date: 2019骞�5鏈�30鏃� 涓婂崍10:58:25 * */ @Configuration public class RedisConfig extends CachingConfigurerSupport { + + @Value("${spring.redis.host}") + private String host; + @Value("${spring.redis.port}") + private int port; + @Value("${spring.redis.database}") + private int database; + @Value("${spring.redis.password}") + private String password; + @Value("${spring.redis.timeout}") + private int timeout; + @Value("${spring.redis.poolMaxTotal:1000}") + private int poolMaxTotal; + @Value("${spring.redis.poolMaxIdle:500}") + private int poolMaxIdle; + @Value("${spring.redis.poolMaxWait:5}") + private int poolMaxWait; + + @Bean + public JedisPool jedisPool() { + if (StringUtils.isBlank(password)) { + password = null; + } + JedisPoolConfig poolConfig = new JedisPoolConfig(); + poolConfig.setMaxIdle(poolMaxIdle); + poolConfig.setMaxTotal(poolMaxTotal); + // 绉掕浆姣 + poolConfig.setMaxWaitMillis(poolMaxWait * 1000L); + JedisPool jp = new JedisPool(poolConfig, host, port, timeout * 1000, password, database); + return jp; + } @Bean("redisTemplate") public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) { @@ -34,7 +69,7 @@ template.setHashKeySerializer(new StringRedisSerializer()); template.setConnectionFactory(redisConnectionFactory); // 浣跨敤fastjson鏃堕渶璁剧疆姝ら」锛屽惁鍒欎細鎶ュ紓甯竛ot support type - ParserConfig.getGlobalInstance().setAutoTypeSupport(true); + ParserConfig.getGlobalInstance().setAutoTypeSupport(true); return template; } @@ -43,7 +78,6 @@ * 閫氳繃鍙嶅皠鎶�鏈皟鐢ㄦ秷鎭闃呭鐞嗗櫒鐨勭浉鍏虫柟娉曡繘琛屼竴浜涗笟鍔″鐞� * * @param connectionFactory - * @param listenerAdapter * @return */ @Bean -- Gitblit v1.8.0