Skip to content

Commit 985cdf7

Browse files
author
litongjava
committed
update redis config
1 parent c0629d4 commit 985cdf7

File tree

1 file changed

+28
-9
lines changed
  • docs/zh/14_jfinal-plugins

1 file changed

+28
-9
lines changed

docs/zh/14_jfinal-plugins/03.md

+28-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ https://central.sonatype.com/artifact/com.litongjava/jfinal-plugins
1212
<dependency>
1313
<groupId>com.litongjava</groupId>
1414
<artifactId>jfinal-plugins</artifactId>
15-
<version>1.0.6</version>
15+
<version>1.0.9</version>
1616
</dependency>
1717
<dependency>
1818
<groupId>redis.clients</groupId>
@@ -32,32 +32,51 @@ https://central.sonatype.com/artifact/com.litongjava/jfinal-plugins
3232
- jedis:3.6.3 连接 reids
3333
- fst:2.57 序列化支持
3434

35+
### app.properties
36+
37+
```
38+
redis.host=127.0.0.1
39+
redis.port=6379
40+
redis.password=
41+
redis.cacheName=main
42+
```
43+
3544
### RedisPluginConfig 配置类
3645

3746
这个类是一个配置类,用于初始化和配置 EhCache 插件。它通过 @AConfiguration 注解标记为配置类。类中的方法 redisPlugin 通过 @ABean 注解标记为 Bean 方法,框架启动时会执行该方法并将返回值放到 bean 容器中。在这个方法中,创建了一个 Plugin 实例并启动它。destroyMethod 指定在服务关闭时将会调用该方法,关闭该插件
3847

3948
```
40-
import com.litongjava.jfinal.aop.annotation.ABean;
49+
4150
import com.litongjava.jfinal.aop.annotation.AConfiguration;
51+
import com.litongjava.jfinal.aop.annotation.AInitialization;
4252
import com.litongjava.jfinal.plugin.redis.Cache;
4353
import com.litongjava.jfinal.plugin.redis.Redis;
4454
import com.litongjava.jfinal.plugin.redis.RedisPlugin;
55+
import com.litongjava.tio.boot.server.TioBootServer;
56+
import com.litongjava.tio.utils.environment.EnvironmentUtils;
4557
4658
@AConfiguration
4759
public class RedisPluginConfig {
4860
49-
@ABean(destroyMethod = "stop")
61+
@AInitialization
5062
public RedisPlugin redisPlugin() {
51-
// 用于缓存bbs模块的redis服务
52-
RedisPlugin bbsRedis = new RedisPlugin("main", "localhost");
53-
bbsRedis.start();
63+
String host = EnvironmentUtils.getStr("redis.host");
64+
Integer port = EnvironmentUtils.getInt("redis.port");
65+
String password = EnvironmentUtils.getStr("redis.password");
66+
String cacheName = EnvironmentUtils.get("redis.cacheName");
67+
68+
// 创建并启动 Redis 插件
69+
RedisPlugin mainRedis = new RedisPlugin(cacheName, host, port, password);
70+
mainRedis.start();
71+
5472
// 测试连接
5573
Cache cache = Redis.use("main");
5674
cache.getJedis().connect();
57-
return bbsRedis;
75+
76+
TioBootServer.me().addDestroyMethod(mainRedis::stop);
77+
return mainRedis;
5878
}
5979
}
60-
6180
```
6281

6382
### 控制器
@@ -158,4 +177,4 @@ public class RedisTestController {
158177
}
159178
```
160179

161-
访问测试 http://localhost/redis/test/test01 http://localhost/redis/test/test02 http://localhost/redis/test/test03
180+
访问测试 http://localhost/redis/test/test01 http://localhost/redis/test/test02 http://localhost/redis/test/test03

0 commit comments

Comments
 (0)