5
5
import redis .clients .jedis .JedisPool ;
6
6
import redis .clients .jedis .JedisPoolConfig ;
7
7
8
+ import java .time .Duration ;
9
+
8
10
/**
9
11
* redis工厂
10
12
* @author Joey
@@ -23,29 +25,31 @@ private RedisFactory() {
23
25
*/
24
26
public static RedisClient createRedisClient (RedisConfig redisConfig ) {
25
27
JedisPoolConfig config = new JedisPoolConfig ();
26
- //最大空闲连接数, 默认8个
27
- config .setMaxIdle (redisConfig .getPool ().getMaxIdle ());
28
28
29
- //最大连接数, 默认8个
30
- config .setMaxTotal (redisConfig .getPool ().getMaxActive ());
29
+ // 最大空闲连接数, 默认8个
30
+ RedisConfig .Pool pool = redisConfig .getPool ();
31
+ config .setMaxIdle (pool .getMaxIdle ());
32
+
33
+ // 最大连接数, 默认8个
34
+ config .setMaxTotal (pool .getMaxActive ());
31
35
32
- //获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1
33
- config .setMaxWaitMillis ( redisConfig . getPool () .getMaxWait ());
36
+ // 获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1
37
+ config .setMaxWait ( Duration . ofMillis ( pool .getMaxWait () ));
34
38
35
- //逐出连接的最小空闲时间 默认1800000毫秒(30分钟)
36
- config .setMinEvictableIdleTimeMillis ( redisConfig . getPool () .getMinEvictableIdleTimeMillis ());
39
+ // 逐出连接的最小空闲时间 默认1800000毫秒(30分钟)
40
+ config .setMinEvictableIdleTime ( Duration . ofMillis ( pool .getMinEvictableIdleTimeMillis () ));
37
41
38
- //最小空闲连接数, 默认0
39
- config .setMinIdle (redisConfig . getPool () .getMinIdle ());
42
+ // 最小空闲连接数, 默认0
43
+ config .setMinIdle (pool .getMinIdle ());
40
44
41
- //在获取连接的时候检查有效性, 默认false
42
- config .setTestOnBorrow (redisConfig . getPool () .isTestOnBorrow ());
45
+ // 在获取连接的时候检查有效性, 默认false
46
+ config .setTestOnBorrow (pool .isTestOnBorrow ());
43
47
44
- //在空闲时检查有效性, 默认false
45
- config .setTestWhileIdle (redisConfig . getPool () .isTestWhileIdle ());
48
+ // 在空闲时检查有效性, 默认false
49
+ config .setTestWhileIdle (pool .isTestWhileIdle ());
46
50
47
- //逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1
48
- config .setTimeBetweenEvictionRunsMillis ( redisConfig . getPool () .getTimeBetweenEvictionRunsMillis ());
51
+ // 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1
52
+ config .setTimeBetweenEvictionRuns ( Duration . ofMillis ( pool .getTimeBetweenEvictionRunsMillis () ));
49
53
50
54
String password = StrUtil .trimToNull (redisConfig .getPassword ());
51
55
JedisPool jedisPool = new JedisPool (config , redisConfig .getHost (),
0 commit comments