Skip to content

Commit a99e6db

Browse files
committedFeb 3, 2025
Java:MultiDataSource-RediSQL 升级 JDK 17,APIJSON 7.1.0, apijson-framework 及自身 7.1.5
1 parent 664776f commit a99e6db

File tree

14 files changed

+100
-45
lines changed

14 files changed

+100
-45
lines changed
 

‎APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/README.md

+32-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,40 @@ Access、Request配置 访问操作权限 <br/>
1212
rediSQL安装使用 <br/>
1313
https://github.com/RedBeardLab/rediSQL
1414

15+
下载 rediSQL.so
16+
https://github.com/RedBeardLab/rediSQL/releases
17+
18+
启动 redis-server 并加载 RediSQL.so
19+
```shell
20+
redis-server --loadmodule RediSQL_<version>.so
21+
```
22+
23+
例如
24+
```shell
25+
redis-server --loadmodule RediSQL_v1.1.1_9b110f__debug.so
26+
```
27+
28+
```shell
29+
redis-server --loadmodule RediSQL_v1.1.1_9b110f__release.so
30+
```
31+
32+
```shell
33+
redis-server --loadmodule RediSQL_v1.1.1_9b110f_x86_64-unknown-linux-gnu_debug.so
34+
```
35+
36+
```shell
37+
redis-server --loadmodule RediSQL_v1.1.1_9b110f_armv7-unknown-linux-gnueabihf_debug.so
38+
```
39+
40+
```shell
41+
redis-server --loadmodule RediSQL_v1.1.1_9b110f_arm-unknown-linux-gnueabi_debug.so
42+
```
43+
1544
官方docker安装 <br/>
45+
```shell
1646
docker pull dalongrong/redisql
1747
docker run -itd --name redisql -p 6399:6379 dalongrong/redisql
48+
```
1849

1950
rediSQL注意事项 <br/>
2051
rediSQL免费版有后遥控制,每个小时会发送 redist info 统计信息<br/>
@@ -30,7 +61,7 @@ https://www.youtube.com/watch?v=YRusC-AIq_g
3061
将 libredis_sql.so 导入redis.config<br/>
3162
--loadmodule /etc/redis/libredis_sql.so<br/>
3263
rediSQL 创建数据库表命令 <br/>
33-
```
64+
```shell
3465
REDISQL.EXEC DB "CREATE TABLE REDIS_TABLE_A(id TEXT, A INT, B TEXT, C TEXT, userId TEXT);"
3566

3667
REDISQL.EXEC DB "INSERT INTO REDIS_TABLE_A(id,A,B,C,userId) VALUES('1', 3, '1c', 'bar','1');"

‎APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/pom.xml

+12-6
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
</parent>
1010
<groupId>apijson.demo</groupId>
1111
<artifactId>apijsondemo-multidatasource-rediSQL</artifactId>
12-
<version>7.0.3</version>
12+
<version>7.1.5</version>
1313

1414
<name>apijsondemo-multidatasource-rediSQL</name>
1515
<description>Demo project for testing APIJSON server based on SpringBoot</description>
1616

1717
<properties>
1818
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1919
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
20+
<java.version>17</java.version>
21+
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
22+
<maven.compiler.source>17</maven.compiler.source>
23+
<maven.compiler.target>17</maven.compiler.target>
2024
<commons-lang3.version>3.12.0</commons-lang3.version>
2125
<druid.version>1.1.16</druid.version>
2226
<mybatisplus.version>3.5.1</mybatisplus.version>
@@ -38,20 +42,19 @@
3842
<spring-boot-configuration-processor.version>2.6.6</spring-boot-configuration-processor.version>
3943
<dynamic-datasource-spring-boot-starter.version>3.5.2</dynamic-datasource-spring-boot-starter.version>
4044
<jedis.version>3.7.1</jedis.version>
41-
<java.version>1.8</java.version>
4245
</properties>
4346

4447
<dependencies>
4548
<!-- 需要的 APIJSON 相关依赖 -->
4649
<dependency>
4750
<groupId>com.github.Tencent</groupId>
4851
<artifactId>APIJSON</artifactId>
49-
<version>7.0.3</version>
52+
<version>7.1.0</version>
5053
</dependency>
5154
<dependency>
5255
<groupId>com.github.APIJSON</groupId>
5356
<artifactId>apijson-framework</artifactId>
54-
<version>7.0.3</version>
57+
<version>7.1.5</version>
5558
</dependency>
5659

5760
<!-- 需要用的数据库 JDBC 驱动 -->
@@ -62,6 +65,7 @@
6265
<dependency>
6366
<groupId>org.springframework.boot</groupId>
6467
<artifactId>spring-boot-starter-web</artifactId>
68+
<version>2.5.13</version>
6569
</dependency>
6670
<dependency>
6771
<groupId>org.springframework</groupId>
@@ -147,6 +151,7 @@
147151
<plugin>
148152
<groupId>org.springframework.boot</groupId>
149153
<artifactId>spring-boot-maven-plugin</artifactId>
154+
<version>2.5.13</version>
150155
<executions>
151156
<execution>
152157
<goals>
@@ -158,9 +163,10 @@
158163
<plugin>
159164
<groupId>org.apache.maven.plugins</groupId>
160165
<artifactId>maven-compiler-plugin</artifactId>
166+
<version>3.8.1</version>
161167
<configuration>
162-
<source>1.8</source>
163-
<target>1.8</target>
168+
<source>17</source>
169+
<target>17</target>
164170
</configuration>
165171
</plugin>
166172
</plugins>

‎APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/src/main/java/apijson/demo/DataBaseConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public String getPrimary() {
1616
return primary;
1717
}
1818

19-
public static DataBaseConfig getInstence() {
19+
public static DataBaseConfig getInstance() {
2020
return SpringContextUtils.getBean(DataBaseConfig.class);
2121
}
2222
}

‎APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/src/main/java/apijson/demo/DemoApplication.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
2626

2727
import apijson.Log;
28-
import apijson.framework.APIJSONApplication;
29-
import apijson.framework.APIJSONCreator;
30-
import apijson.framework.APIJSONParser;
28+
import apijson.framework.javax.APIJSONApplication;
29+
import apijson.framework.javax.APIJSONCreator;
30+
import apijson.framework.javax.APIJSONParser;
3131
import apijson.orm.AbstractFunctionParser;
3232
import apijson.orm.AbstractVerifier;
3333
import apijson.orm.FunctionParser;
@@ -65,11 +65,14 @@ public void customize(ConfigurableServletWebServerFactory server) {
6565

6666
// 支持 APIAuto 中 JavaScript 代码跨域请求
6767
@Bean
68-
public WebMvcConfigurer corsConfigurer() {
68+
public WebMvcConfigurer corsConfig() {
6969
return new WebMvcConfigurer() {
7070
@Override
7171
public void addCorsMappings(CorsRegistry registry) {
72-
registry.addMapping("/**").allowedOriginPatterns("*").allowedMethods("*").allowCredentials(true)
72+
registry.addMapping("/**")
73+
.allowedOriginPatterns("*")
74+
.allowedMethods("*")
75+
.allowCredentials(true)
7376
.maxAge(3600);
7477
}
7578
};
@@ -84,17 +87,17 @@ public Parser<String> createParser() {
8487
}
8588

8689
@Override
87-
public SQLConfig createSQLConfig() {
90+
public SQLConfig<String> createSQLConfig() {
8891
return new DemoSQLConfig();
8992
}
9093

9194
@Override
92-
public FunctionParser createFunctionParser() {
95+
public FunctionParser<String> createFunctionParser() {
9396
return new DemoFunctionParser();
9497
}
9598

9699
@Override
97-
public SQLExecutor createSQLExecutor() {
100+
public SQLExecutor<String> createSQLExecutor() {
98101
return new DemoSQLExecutor();
99102
}
100103
};

‎APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/src/main/java/apijson/demo/DemoController.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import apijson.RequestMethod;
3131
import apijson.StringUtil;
32-
import apijson.framework.APIJSONController;
32+
import apijson.framework.javax.APIJSONController;
3333
import apijson.orm.Parser;
3434

3535

@@ -46,10 +46,10 @@
4646
*/
4747
@RestController
4848
@RequestMapping("")
49-
public class DemoController extends APIJSONController<Long> {
49+
public class DemoController extends APIJSONController<String> {
5050

5151
@Override
52-
public Parser<Long> newParser(HttpSession session, RequestMethod method) {
52+
public Parser<String> newParser(HttpSession session, RequestMethod method) {
5353
return super.newParser(session, method).setNeedVerify(false); // TODO 这里关闭校验,方便新手快速测试,实际线上项目建议开启
5454
}
5555

‎APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/src/main/java/apijson/demo/DemoFunctionParser.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import apijson.NotNull;
88
import apijson.RequestMethod;
99
import apijson.StringUtil;
10-
import apijson.framework.APIJSONFunctionParser;
11-
import apijson.framework.APIJSONVerifier;
10+
import apijson.framework.javax.APIJSONFunctionParser;
11+
import apijson.framework.javax.APIJSONVerifier;
1212
import lombok.extern.slf4j.Slf4j;
1313

1414
@Slf4j
15-
public class DemoFunctionParser extends APIJSONFunctionParser {
15+
public class DemoFunctionParser extends APIJSONFunctionParser<String> {
1616
public DemoFunctionParser() {
1717
this(null, null, 0, null, null);
1818
}

‎APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/src/main/java/apijson/demo/DemoObjectParser.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
import apijson.NotNull;
1010
import apijson.RequestMethod;
11-
import apijson.framework.APIJSONObjectParser;
11+
import apijson.framework.javax.APIJSONObjectParser;
1212
import apijson.orm.Join;
1313
import apijson.orm.SQLConfig;
1414

15-
public class DemoObjectParser extends APIJSONObjectParser {
15+
public class DemoObjectParser extends APIJSONObjectParser<String> {
1616

1717
public DemoObjectParser(HttpSession session, @NotNull JSONObject request, String parentPath, SQLConfig arrayConfig
1818
, boolean isSubquery, boolean isTable, boolean isArrayMainTable) throws Exception {

‎APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/src/main/java/apijson/demo/DemoParser.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import com.alibaba.fastjson.JSONObject;
44

55
import apijson.RequestMethod;
6-
import apijson.framework.APIJSONObjectParser;
7-
import apijson.framework.APIJSONParser;
6+
import apijson.framework.javax.APIJSONObjectParser;
7+
import apijson.framework.javax.APIJSONParser;
88
import apijson.orm.SQLConfig;
99

1010
public class DemoParser extends APIJSONParser<String> {
@@ -27,7 +27,7 @@ public DemoParser(RequestMethod method, boolean needVerify) {
2727
// }
2828

2929
@Override
30-
public APIJSONObjectParser createObjectParser(JSONObject request, String parentPath, SQLConfig arrayConfig, boolean isSubquery, boolean isTable, boolean isArrayMainTable) throws Exception {
30+
public APIJSONObjectParser<String> createObjectParser(JSONObject request, String parentPath, SQLConfig arrayConfig, boolean isSubquery, boolean isTable, boolean isArrayMainTable) throws Exception {
3131
return new DemoObjectParser(getSession(), request, parentPath, arrayConfig, isSubquery, isTable, isArrayMainTable).setMethod(getMethod()).setParser(this);
3232
}
3333

‎APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/src/main/java/apijson/demo/DemoSQLConfig.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.alibaba.fastjson.annotation.JSONField;
2020

2121
import apijson.RequestMethod;
22-
import apijson.framework.APIJSONSQLConfig;
22+
import apijson.framework.javax.APIJSONSQLConfig;
2323
import apijson.orm.AbstractSQLConfig;
2424

2525

@@ -29,7 +29,7 @@
2929
* https://github.com/Tencent/APIJSON/blob/master/%E8%AF%A6%E7%BB%86%E7%9A%84%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md#c-1-1%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E9%93%BE%E6%8E%A5
3030
* @author Lemon
3131
*/
32-
public class DemoSQLConfig extends APIJSONSQLConfig<Long> {
32+
public class DemoSQLConfig extends APIJSONSQLConfig<String> {
3333

3434
public DemoSQLConfig() {
3535
super();

‎APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/src/main/java/apijson/demo/DemoSQLExecutor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import apijson.NotNull;
2626
import apijson.StringUtil;
2727
import apijson.demo.resultSet.DataBuildResultSet;
28-
import apijson.framework.APIJSONSQLExecutor;
28+
import apijson.framework.javax.APIJSONSQLExecutor;
2929
import apijson.orm.SQLConfig;
3030
import lombok.extern.log4j.Log4j2;
3131

@@ -35,7 +35,7 @@
3535
* @author Lemon
3636
*/
3737
@Log4j2
38-
public class DemoSQLExecutor extends APIJSONSQLExecutor<Long> {
38+
public class DemoSQLExecutor extends APIJSONSQLExecutor<String> {
3939
public static final String TAG = "DemoSQLExecutor";
4040

4141
// 适配连接池,如果这里能拿到连接池的有效 Connection,则 SQLConfig 不需要配置 dbVersion, dbUri, dbAccount,

‎APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/src/main/java/apijson/demo/DynamicDataSource.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static void addDataSource(DynamicDataSource detail) {
6565
public static DynamicDataSource getDetail(String datasource) {
6666
if (datasource == null) {
6767
// 默认数据源
68-
datasource = DataBaseConfig.getInstence().getPrimary();
68+
datasource = DataBaseConfig.getInstance().getPrimary();
6969
}
7070
// 不存在交给框架处理
7171
return dataSourceMap.get(datasource);

‎APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/src/main/java/apijson/demo/JedisClusterUtil.java

+18-8
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,22 @@ public class JedisClusterUtil {
5151
*/
5252
public void createJedisPool() {
5353
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
54-
jedisClusterNode.add(new HostAndPort("127.0.0.1", 6371));
55-
jedisClusterNode.add(new HostAndPort("127.0.0.1", 6372));
56-
jedisClusterNode.add(new HostAndPort("127.0.0.1", 6373));
57-
jedisClusterNode.add(new HostAndPort("127.0.0.1", 6374));
58-
jedisClusterNode.add(new HostAndPort("127.0.0.1", 6375));
59-
jedisClusterNode.add(new HostAndPort("127.0.0.1", 6376));
54+
//jedisClusterNode.add(new HostAndPort("127.0.0.1", 6379));
55+
56+
// TODO 至少启动 6 个节点,参考教程 https://medium.com/@bertrandoubida/setting-up-redis-cluster-on-macos-cf35a21465a
57+
jedisClusterNode.add(new HostAndPort("127.0.0.1", 6380));
58+
jedisClusterNode.add(new HostAndPort("127.0.0.1", 6381));
59+
jedisClusterNode.add(new HostAndPort("127.0.0.1", 6382));
60+
jedisClusterNode.add(new HostAndPort("127.0.0.1", 6383));
61+
jedisClusterNode.add(new HostAndPort("127.0.0.1", 6384));
62+
jedisClusterNode.add(new HostAndPort("127.0.0.1", 6385));
63+
64+
//jedisClusterNode.add(new HostAndPort("127.0.0.1", 6371));
65+
//jedisClusterNode.add(new HostAndPort("127.0.0.1", 6372));
66+
//jedisClusterNode.add(new HostAndPort("127.0.0.1", 6373));
67+
//jedisClusterNode.add(new HostAndPort("127.0.0.1", 6374));
68+
//jedisClusterNode.add(new HostAndPort("127.0.0.1", 6375));
69+
//jedisClusterNode.add(new HostAndPort("127.0.0.1", 6376));
6070
JedisPoolConfig poolConfig = new JedisPoolConfig();
6171
/*
6272
* 注意: 在高版本的jedis jar包,比如本版本2.9.0,JedisPoolConfig没有setMaxActive和setMaxWait属性了
@@ -73,7 +83,8 @@ public void createJedisPool() {
7383
int maxAttempts = 5;
7484
// JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT,
7585
// DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
76-
jedisCluster = new JedisCluster(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, PASSWORD, poolConfig);
86+
jedisCluster = new JedisCluster(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, poolConfig); // TODO 如果需要密码则用下面一行代码,并设置正确的密码
87+
//jedisCluster = new JedisCluster(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, PASSWORD, poolConfig);
7788
log.info("节点信息:{}", jedisCluster.getClusterNodes().keySet());
7889
}
7990

@@ -92,7 +103,6 @@ public void setJedis(String db) {
92103
public Jedis getJedis(String key) {
93104
int slot = JedisClusterCRC16.getSlot(key);
94105
return jedisCluster.getConnectionFromSlot(slot);
95-
96106
}
97107

98108
private String ok_returns(RediSQLCommand.ModuleCommand cmd, String... args) {

‎APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/src/main/java/com/redbeardlab/redisql/client/ParseRediSQLReply.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@
44

55
public class ParseRediSQLReply {
66
public static boolean done_reply(List<Object> reply) {
7-
if (reply.size() != 2) { return false; }
8-
if ((reply.get(0) instanceof byte[]) && (new String((byte[])reply.get(0)).equals("DONE"))) {
7+
if (reply == null || reply.size() != 2) {
8+
return false;
9+
}
10+
11+
Object first = reply.get(0);
12+
if ((first instanceof byte[]) && (new String((byte[]) first).equals("DONE"))) {
913
return (reply.get(1) instanceof Long);
1014
}
15+
1116
return false;
1217
}
1318

1419
public static Long how_many_done(List<Object> reply) {
15-
if (reply == null || reply.size() == 0 ||done_reply(reply) == false) {
20+
if (reply == null || reply.isEmpty() || ! done_reply(reply)) {
1621
return 0L;
1722
}
18-
return (Long)reply.get(1);
23+
return (Long) reply.get(1);
1924
}
2025

2126
public static boolean is_integer(Object o) {

‎APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/src/main/resources/application.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ spring:
2222
datasource:
2323
master:
2424
driver-class-name: com.mysql.cj.jdbc.Driver
25-
url: jdbc:mysql://localhost:3306/sys?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&useSSL=false
25+
url: jdbc:mysql://localhost:3306?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true&useSSL=false
2626
username: root
2727
password: apijson
2828
filter:

0 commit comments

Comments
 (0)
Please sign in to comment.