|
2 | 2 |
|
3 | 3 | 添加依赖,tio-boot 已经内置了 hutool-all 以来,包含 hutool-redis,主要添加 jedis 依赖即可
|
4 | 4 |
|
5 |
| -``` |
| 5 | +```xml |
6 | 6 | <dependency>
|
7 | 7 | <groupId>redis.clients</groupId>
|
8 | 8 | <artifactId>jedis</artifactId>
|
|
12 | 12 |
|
13 | 13 | 配置类
|
14 | 14 |
|
15 |
| -``` |
16 |
| -package com.litongjava.tio.boot.hello.config; |
| 15 | +```java |
| 16 | +package com.imaginix.kimi.service.monitoring.config; |
| 17 | + |
| 18 | +import com.jfinal.kit.StrKit; |
| 19 | +import com.litongjava.jfinal.aop.annotation.ABean; |
| 20 | +import com.litongjava.jfinal.aop.annotation.AConfiguration; |
| 21 | +import com.litongjava.tio.utils.environment.EnvironmentUtils; |
17 | 22 |
|
18 | 23 | import cn.hutool.db.nosql.redis.RedisDS;
|
19 | 24 | import cn.hutool.setting.Setting;
|
20 |
| -import com.jfinal.kit.StrKit; |
21 |
| -import com.litongjava.jfinal.aop.Aop; |
22 |
| -import com.litongjava.jfinal.aop.annotation.Bean; |
23 |
| -import com.litongjava.jfinal.aop.annotation.Configuration; |
24 |
| -import com.litongjava.tio.boot.context.Enviorment; |
25 |
| -import redis.clients.jedis.Jedis; |
26 |
| -import redis.clients.jedis.JedisPool; |
27 |
| -import redis.clients.jedis.JedisPoolConfig; |
28 | 25 | import redis.clients.jedis.Protocol;
|
29 | 26 |
|
30 | 27 | @AConfiguration
|
31 | 28 | public class HutoolRedisConfig {
|
32 | 29 | @ABean(destroyMethod = "close")
|
33 | 30 | public RedisDS redisDS() {
|
34 |
| - Enviorment enviorment = Aop.get(Enviorment.class); |
35 |
| - String redisHost = enviorment.get("redis.host", "127.0.0.1"); |
36 |
| - String redisPort = enviorment.get("redis.port", "6379"); |
37 |
| - String redisPassword = enviorment.get("redis.password"); |
| 31 | + String redisHost = EnvironmentUtils.get("redis.host", "127.0.0.1"); |
| 32 | + String redisPort = EnvironmentUtils.get("redis.port", "6379"); |
| 33 | + String redisPassword = EnvironmentUtils.get("redis.password"); |
38 | 34 |
|
39 | 35 | // 配置你的Redis连接信息
|
40 | 36 | Setting setting = new Setting();
|
@@ -62,7 +58,7 @@ public class HutoolRedisConfig {
|
62 | 58 | // 是否使用SSL
|
63 | 59 | setting.setByGroup("ssl", group, String.valueOf(false));
|
64 | 60 | RedisDS redisDS = new RedisDS(setting, group);
|
65 |
| - //连接redis |
| 61 | + // 连接redis |
66 | 62 | redisDS.getJedis();
|
67 | 63 | return redisDS;
|
68 | 64 | }
|
@@ -128,4 +124,4 @@ public class HuRedisTestController {
|
128 | 124 | - 如果值不存在(`null`),则记录信息并使用 `redisDS.setStr("key", "value")` 设置新的键值对。
|
129 | 125 | - 返回从 Redis 获取的值(如果之前不存在,则为 `null`)。
|
130 | 126 |
|
131 |
| -这段代码展示了如何使用 Hutool 提供的 `RedisDS` 类在 tio-boot 框架中配置和访问 Redis 数据库。配置类 `HutoolRedisConfig` 负责设置 Redis 连接,而控制器类 `HuRedisTestController` 则处理具体的 Redis 交互逻辑。 |
| 127 | +这段代码展示了如何使用 Hutool 提供的 `RedisDS` 类在 tio-boot 框架中配置和访问 Redis 数据库。配置类 `HutoolRedisConfig` 负责设置 Redis 连接,而控制器类 `HuRedisTestController` 则处理具体的 Redis 交互逻辑。 |
0 commit comments