Skip to content

Commit 788b47c

Browse files
author
litongjava
committed
update redisconfig
1 parent ff54dc0 commit 788b47c

File tree

1 file changed

+10
-3
lines changed
  • docs/zh/14_jfinal-plugins

1 file changed

+10
-3
lines changed

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

+10-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ https://central.sonatype.com/artifact/com.litongjava/jfinal-plugins
3636

3737
```
3838
redis.host=127.0.0.1
39-
redis.port=6379
39+
redis.port=6789
4040
redis.password=
41+
redis.database=2
42+
redis.timeout=15000
4143
redis.cacheName=main
4244
```
4345

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

4850
```
51+
package com.litongjava.tio.boot.admin.config;
4952
5053
import com.litongjava.jfinal.aop.annotation.AConfiguration;
5154
import com.litongjava.jfinal.aop.annotation.AInitialization;
@@ -63,20 +66,24 @@ public class RedisPluginConfig {
6366
String host = EnvironmentUtils.getStr("redis.host");
6467
Integer port = EnvironmentUtils.getInt("redis.port");
6568
String password = EnvironmentUtils.getStr("redis.password");
69+
int redistimeout = EnvironmentUtils.getInt("redis.timeout", 60);
70+
int redisDatabase = EnvironmentUtils.getInt("redis.database", 0);
6671
String cacheName = EnvironmentUtils.get("redis.cacheName");
6772
6873
// 创建并启动 Redis 插件
69-
RedisPlugin mainRedis = new RedisPlugin(cacheName, host, port, password);
74+
RedisPlugin mainRedis = new RedisPlugin(cacheName, host, port, redistimeout, password, redisDatabase);
7075
mainRedis.start();
7176
7277
// 测试连接
73-
Cache cache = Redis.use("main");
78+
Cache cache = Redis.use(cacheName);
7479
cache.getJedis().connect();
7580
7681
TioBootServer.me().addDestroyMethod(mainRedis::stop);
7782
return mainRedis;
7883
}
7984
}
85+
86+
8087
```
8188

8289
### 控制器

0 commit comments

Comments
 (0)