Skip to content

Commit fa17d85

Browse files
committed
add jedis sample
1 parent d27dfec commit fa17d85

5 files changed

Lines changed: 89 additions & 14 deletions

File tree

springboot-jedis-sample/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
<artifactId>spring-boot-starter-test</artifactId>
3030
<scope>test</scope>
3131
</dependency>
32+
33+
<dependency>
34+
<groupId>redis.clients</groupId>
35+
<artifactId>jedis</artifactId>
36+
<version>2.9.0</version>
37+
</dependency>
3238
</dependencies>
3339

3440
<build>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.ipman.springboot.redis.jedis.sample.config;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import redis.clients.jedis.JedisPool;
7+
import redis.clients.jedis.JedisPoolConfig;
8+
9+
/**
10+
* Created by ipipman on 2021/1/6.
11+
*
12+
* @version V1.0
13+
* @Package com.ipman.springboot.redis.jedis.sample.config
14+
* @Description: (用一句话描述该文件做什么)
15+
* @date 2021/1/6 10:11 下午
16+
*/
17+
@Configuration
18+
public class RedisConfig {
19+
20+
@Value("${spring.redis.host}")
21+
private String host;
22+
23+
@Value("${spring.redis.port}")
24+
private int port;
25+
26+
@Value("${spring.redis.timeout}")
27+
private int timeout;
28+
29+
@Value("${spring.redis.jedis.pool.max-idle}")
30+
private int maxIdle;
31+
32+
@Value("${spring.redis.jedis.pool.max-wait}")
33+
private long maxWaitMillis;
34+
35+
@Value("${spring.redis.password}")
36+
private String password;
37+
38+
@Value("${spring.redis.block-when-exhausted}")
39+
private boolean blockWhenExhausted;
40+
41+
@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);
51+
}
52+
}
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
1+
#Redis默认库
2+
spring.redis.database=0
3+
#Redis地址
4+
spring.redis.host=10.211.55.6
5+
#Redis端口
6+
spring.redis.port=6379
7+
#Redis密码
8+
spring.redis.password=
9+
spring.redis.jedis.pool.max-active=1024
10+
spring.redis.jedis.pool.max-wait=10000
11+
spring.redis.jedis.pool.max-idle=200
12+
spring.redis.jedis.pool.min-idle=0
13+
spring.redis.timeout=10000
14+
spring.redis.block-when-exhausted=true
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.ipman.springboot.redis.jedis.sample;
2+
3+
import org.springframework.boot.test.context.SpringBootTest;
4+
5+
/**
6+
* Created by ipipman on 2021/1/6.
7+
*
8+
* @version V1.0
9+
* @Package com.ipman.springboot.redis.jedis.sample
10+
* @Description: (用一句话描述该文件做什么)
11+
* @date 2021/1/6 10:00 上午
12+
*/
13+
@SpringBootTest
14+
public class JedisTest {
15+
16+
17+
}

springboot-jedis-sample/src/test/java/com/ipman/springboot/redis/jedis/sample/SpringbootJedisSampleApplicationTests.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)