|
1 | 1 | package com.ipman.springboot.redis.jedis.sample.config; |
2 | 2 |
|
3 | 3 | import org.springframework.beans.factory.annotation.Value; |
| 4 | +import org.springframework.boot.context.properties.ConfigurationProperties; |
4 | 5 | import org.springframework.context.annotation.Bean; |
5 | 6 | import org.springframework.context.annotation.Configuration; |
6 | 7 | import redis.clients.jedis.JedisPool; |
@@ -36,17 +37,17 @@ public class RedisConfig { |
36 | 37 | private String password; |
37 | 38 |
|
38 | 39 | @Value("${spring.redis.block-when-exhausted}") |
39 | | - private boolean blockWhenExhausted; |
| 40 | + private boolean blockWhenExhausted; |
40 | 41 |
|
41 | 42 | @Bean |
42 | | - public JedisPool redisPoolFactory() throws Exception{ |
43 | | - JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); |
44 | | - jedisPoolConfig.setMaxIdle(maxIdle); |
45 | | - jedisPoolConfig.setMaxWaitMillis(maxWaitMillis); |
46 | | - // 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true |
47 | | - jedisPoolConfig.setBlockWhenExhausted(blockWhenExhausted); |
48 | | - // 是否启用pool的jmx管理功能, 默认true |
49 | | - jedisPoolConfig.setJmxEnabled(true); |
50 | | - return new JedisPool(jedisPoolConfig, host, port, timeout, password); |
| 43 | + @ConfigurationProperties("redis") |
| 44 | + public JedisPoolConfig jedisPoolConfig() { |
| 45 | + return new JedisPoolConfig(); |
| 46 | + } |
| 47 | + |
| 48 | + @Bean(destroyMethod = "close") |
| 49 | + public JedisPool jedisPool() { |
| 50 | + JedisPool jedisPool = new JedisPool(jedisPoolConfig(), host, port, timeout * 1000); |
| 51 | + return jedisPool; |
51 | 52 | } |
52 | 53 | } |
0 commit comments