Ver código fonte

增加redis的配置

xusl 3 anos atrás
pai
commit
f2541458af

+ 45 - 0
ipfcst-console/src/main/java/com/jiayue/ipfcst/config/RedisConfig.java

@@ -0,0 +1,45 @@
+package com.jiayue.ipfcst.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.JedisPoolConfig;
+
+@Configuration
+public class RedisConfig {
+    @Value("${spring.redis.host}")
+    private String host;
+
+    @Value("${spring.redis.port}")
+    private int port;
+
+    @Value("${spring.redis.timeout}")
+    private int timeout;
+
+    @Value("${spring.redis.maxIdle}")
+    private int maxIdle;
+
+    @Value("${spring.redis.maxWaitMillis}")
+    private int maxWaitMillis;
+
+    @Value("${spring.redis.blockWhenExhausted}")
+    private Boolean blockWhenExhausted;
+
+    @Value("${spring.redis.JmxEnabled}")
+    private Boolean JmxEnabled;
+
+    @Bean
+    public JedisPool jedisPoolFactory() {
+        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
+        jedisPoolConfig.setMaxIdle(maxIdle);
+        jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
+        // 连接耗尽时是否阻塞, false报异常,true阻塞直到超时, 默认true
+        jedisPoolConfig.setBlockWhenExhausted(blockWhenExhausted);
+        // 是否启用pool的jmx管理功能, 默认true
+        jedisPoolConfig.setJmxEnabled(JmxEnabled);
+        JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout);
+        return jedisPool;
+    }
+}