Skip to content

Commit 3489227

Browse files
authored
新增 RediSQL Demo,支持 Redis 零代码 CRUD,感谢 cloudAndMonkey 的贡献 #31
https://github.com/APIJSON/APIJSON-Demo/tree/master/APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/README.md
2 parents 5231ad2 + 4d50697 commit 3489227

22 files changed

+3990
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# APIJSONDemo
2+
3+
## 支持多数据源-rediSQL
4+
5+
redis table 表名规范: REDIS_TABLE_* <br/>
6+
开发人员可自行控制 <br/>
7+
JedisBuildData <br/>
8+
public static final String REDIS_TABLE_KEY = "REDIS_TABLE_"; // rediSql table prefix <br/>
9+
10+
Access、Request配置 访问操作权限 <br/>
11+
12+
rediSQL安装使用 <br/>
13+
https://github.com/RedBeardLab/rediSQL
14+
15+
官方docker安装 <br/>
16+
docker pull dalongrong/redisql
17+
docker run -itd --name redisql -p 6399:6379 dalongrong/redisql
18+
19+
rediSQL注意事项 <br/>
20+
rediSQL免费版有后遥控制,每个小时会发送 redist info 统计信息<br/>
21+
<img width="1000" alt="image" src="https://user-images.githubusercontent.com/12228225/219613765-e8d4d963-035b-4352-9552-1ce3a14093e4.png">
22+
23+
可以配host ,弄一个nginx 本地代理 解决,或者 项目自己重新打包<br/>
24+
25+
rediSQL java:<br/>
26+
https://github.com/RedBeardLab/JRediSQL<br/>
27+
https://www.youtube.com/watch?v=YRusC-AIq_g
28+
29+
本示例 用 redis cluster rediSQL, 具体redis集群模式, 开发人员自行控制<br/>
30+
将 libredis_sql.so 导入redis.config<br/>
31+
--loadmodule /etc/redis/libredis_sql.so<br/>
32+
rediSQL 创建数据库表命令 <br/>
33+
```
34+
REDISQL.EXEC DB "CREATE TABLE REDIS_TABLE_A(id TEXT, A INT, B TEXT, C TEXT, userId TEXT);"
35+
36+
REDISQL.EXEC DB "INSERT INTO REDIS_TABLE_A(id,A,B,C,userId) VALUES('1', 3, '1c', 'bar','1');"
37+
38+
39+
REDISQL.EXEC DB "SELECT * FROM REDIS_TABLE_A;"
40+
41+
REDISQL.EXEC DB "drop table REDIS_TABLE_A;"
42+
```
43+
44+
测试用例<br/>
45+
```
46+
{
47+
"@datasource": "redisCluster",
48+
"REDIS_TABLE_A":{
49+
"A": 1,
50+
"B": "B",
51+
"C": "C"
52+
},
53+
"tag": "REDIS_TABLE_A",
54+
"@explain": true,
55+
"format": true
56+
}
57+
58+
{
59+
"REDIS_TABLE_A[]": [
60+
{
61+
"A": 5,
62+
"B": "5B",
63+
"C": "5C"
64+
},
65+
{
66+
"A": 6,
67+
"B": "6B",
68+
"C": "6C"
69+
},
70+
{
71+
"A": 7,
72+
"B": "7B",
73+
"C": "7C"
74+
}
75+
],
76+
"tag": "REDIS_TABLE_A[]",
77+
"@datasource": "redisCluster",
78+
"@explain": true,
79+
"format": true
80+
}
81+
82+
{
83+
"@datasource": "redisCluster",
84+
"REDIS_TABLE_A": {
85+
"id": "f2621698-99fa-4698-9fb0-8c7b585da403",
86+
"A": 1,
87+
"B": "1B"
88+
},
89+
"tag": "REDIS_TABLE_A",
90+
"@explain": true,
91+
"format": true
92+
}
93+
94+
Request 表配置
95+
{"REDIS_TABLE_A[]": [{"MUST": "A,B", "REFUSE": "id"}], "INSERT": {"@role": "OWNER,ADMIN","@combine": "A | B"}}
96+
97+
{
98+
"@datasource": "redisCluster",
99+
"REDIS_TABLE_A": {
100+
"A": 1,
101+
"B": "1B",
102+
"C": "1-1-1C"
103+
},
104+
"tag": "REDIS_TABLE_A",
105+
"@explain": true,
106+
"format": true
107+
}
108+
109+
{
110+
"@datasource": "redisCluster",
111+
"REDIS_TABLE_A:a": {
112+
"@column":"a,b,c",
113+
"b$": "7B%"
114+
},
115+
"@explain": true,
116+
"format": true
117+
}
118+
119+
{
120+
"@datasource": "redisCluster",
121+
"REDIS_TABLE_A:a[]": {
122+
"REDIS_TABLE_A": {
123+
"@column":"a,b,c"
124+
//"b$": "1%"
125+
},
126+
"page":0,
127+
"count":3,
128+
"query": 2
129+
},
130+
"total@": "/REDIS_TABLE_A:a[]/total",
131+
"@explain": true,
132+
"format": true
133+
}
134+
135+
{
136+
"@datasource": "redisCluster",
137+
"REDIS_TABLE_A": {
138+
"id": "f2621698-99fa-4698-9fb0-8c7b585da403"
139+
},
140+
"tag": "REDIS_TABLE_A",
141+
"@explain": true,
142+
"format": true
143+
}
144+
145+
{
146+
"@datasource": "redisCluster",
147+
"REDIS_TABLE_A:a": {
148+
"id{}": ["1","eb3dd7c9-bab6-410c-b70a-cbbc3bd12896", "c83b3cfa-034e-4a9e-b2cf-83520db1ce05"]
149+
},
150+
"tag": "REDIS_TABLE_A[]",
151+
"@explain": true,
152+
"format": true
153+
}
154+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.springframework.boot</groupId>
6+
<artifactId>spring-boot-starter-parent</artifactId>
7+
<version>2.5.13</version>
8+
<!-- <relativePath>./pom.xml</relativePath>-->
9+
</parent>
10+
<groupId>apijson.demo</groupId>
11+
<artifactId>apijsondemo-multidatasource-rediSQL</artifactId>
12+
<version>6.0.0</version>
13+
14+
<name>apijsondemo-multidatasource-rediSQL</name>
15+
<description>Demo project for testing APIJSON server based on SpringBoot</description>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
20+
<commons-lang3.version>3.12.0</commons-lang3.version>
21+
<druid.version>1.1.16</druid.version>
22+
<mybatisplus.version>3.5.1</mybatisplus.version>
23+
<mybatis-plus-support.version>2.3.3</mybatis-plus-support.version>
24+
<commons-collections4.version>4.4</commons-collections4.version>
25+
<commons.configuration.version>1.10</commons.configuration.version>
26+
<guava.version>30.1.1-jre</guava.version>
27+
<fastjson.version>1.2.72</fastjson.version>
28+
<hutool.version>4.1.1</hutool.version>
29+
<lombok.version>1.18.4</lombok.version>
30+
<commons-lang3.version>3.12.0</commons-lang3.version>
31+
<commons.io.version>2.5</commons.io.version>
32+
<commons.codec.version>1.10</commons.codec.version>
33+
<commons-collections4.version>4.4</commons-collections4.version>
34+
<commons.configuration.version>1.10</commons.configuration.version>
35+
<apijson.version>6.0.0</apijson.version>
36+
<mysql.version>8.0.31</mysql.version>
37+
<spring-context-support.version>5.3.18</spring-context-support.version>
38+
<spring-boot-configuration-processor.version>2.6.6</spring-boot-configuration-processor.version>
39+
<dynamic-datasource-spring-boot-starter.version>3.5.2</dynamic-datasource-spring-boot-starter.version>
40+
<jedis.version>3.7.1</jedis.version>
41+
<java.version>1.8</java.version>
42+
</properties>
43+
44+
<dependencies>
45+
<!-- 需要的 APIJSON 相关依赖 -->
46+
<dependency>
47+
<groupId>com.github.Tencent</groupId>
48+
<artifactId>APIJSON</artifactId>
49+
<version>${apijson.version}</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>com.github.APIJSON</groupId>
53+
<artifactId>apijson-framework</artifactId>
54+
<version>${apijson.version}</version>
55+
</dependency>
56+
57+
<!-- 需要用的数据库 JDBC 驱动 -->
58+
59+
<!-- Oracle, SQLServer 等其它数据库的 JDBC 驱动,可以在这里加上 Maven 依赖或 libs 目录放 Jar 包并依赖 -->
60+
61+
<!-- 需要用的 SpringBoot 框架,1.4.0 以上 -->
62+
<dependency>
63+
<groupId>org.springframework.boot</groupId>
64+
<artifactId>spring-boot-starter-web</artifactId>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.springframework</groupId>
68+
<artifactId>spring-context-support</artifactId>
69+
<version>${spring-context-support.version}</version>
70+
</dependency>
71+
<dependency>
72+
<groupId>org.springframework.boot</groupId>
73+
<artifactId>spring-boot-configuration-processor</artifactId>
74+
<version>${spring-boot-configuration-processor.version}</version>
75+
<optional>true</optional>
76+
</dependency>
77+
<dependency>
78+
<groupId>com.alibaba</groupId>
79+
<artifactId>druid-spring-boot-starter</artifactId>
80+
<version>${druid.version}</version>
81+
</dependency>
82+
<dependency>
83+
<groupId>com.baomidou</groupId>
84+
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
85+
<version>${dynamic-datasource-spring-boot-starter.version}</version>
86+
</dependency>
87+
<dependency>
88+
<groupId>com.baomidou</groupId>
89+
<artifactId>mybatis-plus-boot-starter</artifactId>
90+
<version>${mybatisplus.version}</version>
91+
<exclusions>
92+
<exclusion>
93+
<groupId>com.baomidou</groupId>
94+
<artifactId>mybatis-plus-generator</artifactId>
95+
</exclusion>
96+
</exclusions>
97+
</dependency>
98+
<dependency>
99+
<groupId>com.baomidou</groupId>
100+
<artifactId>mybatis-plus-support</artifactId>
101+
<version>${mybatis-plus-support.version}</version>
102+
</dependency>
103+
<dependency>
104+
<groupId>org.apache.commons</groupId>
105+
<artifactId>commons-collections4</artifactId>
106+
<version>${commons-collections4.version}</version>
107+
</dependency>
108+
<dependency>
109+
<groupId>mysql</groupId>
110+
<artifactId>mysql-connector-java</artifactId>
111+
<version>${mysql.version}</version>
112+
</dependency>
113+
<dependency>
114+
<groupId>com.google.guava</groupId>
115+
<artifactId>guava</artifactId>
116+
<version>${guava.version}</version>
117+
</dependency>
118+
<dependency>
119+
<groupId>org.projectlombok</groupId>
120+
<artifactId>lombok</artifactId>
121+
<version>${lombok.version}</version>
122+
</dependency>
123+
<dependency>
124+
<groupId>commons-io</groupId>
125+
<artifactId>commons-io</artifactId>
126+
<version>${commons.io.version}</version>
127+
</dependency>
128+
<dependency>
129+
<groupId>commons-codec</groupId>
130+
<artifactId>commons-codec</artifactId>
131+
<version>${commons.codec.version}</version>
132+
</dependency>
133+
<dependency>
134+
<groupId>commons-configuration</groupId>
135+
<artifactId>commons-configuration</artifactId>
136+
<version>${commons.configuration.version}</version>
137+
</dependency>
138+
<dependency>
139+
<groupId>redis.clients</groupId>
140+
<artifactId>jedis</artifactId>
141+
<version>${jedis.version}</version>
142+
</dependency>
143+
</dependencies>
144+
145+
<build>
146+
<plugins>
147+
<plugin>
148+
<groupId>org.springframework.boot</groupId>
149+
<artifactId>spring-boot-maven-plugin</artifactId>
150+
<configuration>
151+
<fork>true</fork>
152+
<mainClass>apijson.demo.DemoApplication</mainClass>
153+
</configuration>
154+
<executions>
155+
<execution>
156+
<goals>
157+
<goal>repackage</goal>
158+
</goals>
159+
</execution>
160+
</executions>
161+
</plugin>
162+
<plugin>
163+
<groupId>org.apache.maven.plugins</groupId>
164+
<artifactId>maven-compiler-plugin</artifactId>
165+
<configuration>
166+
<source>1.8</source>
167+
<target>1.8</target>
168+
</configuration>
169+
</plugin>
170+
</plugins>
171+
</build>
172+
173+
<repositories>
174+
<!-- APIJSON 必须用到的托管平台 -->
175+
<repository>
176+
<id>jitpack.io</id>
177+
<url>https://jitpack.io</url>
178+
<snapshots>
179+
<enabled>true</enabled>
180+
</snapshots>
181+
</repository>
182+
183+
<repository>
184+
<id>spring-snapshots</id>
185+
<url>https://repo.spring.io/snapshot</url>
186+
<snapshots>
187+
<enabled>true</enabled>
188+
</snapshots>
189+
</repository>
190+
<repository>
191+
<id>spring-milestones</id>
192+
<url>https://repo.spring.io/milestone</url>
193+
</repository>
194+
</repositories>
195+
196+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package apijson.demo;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
@Configuration
7+
public class DataBaseConfig {
8+
private String primary;
9+
10+
@Value("${spring.datasource.dynamic.primary}")
11+
public void setPrimary(String primary) {
12+
this.primary = primary;
13+
}
14+
15+
public String getPrimary() {
16+
return primary;
17+
}
18+
19+
public static DataBaseConfig getInstence() {
20+
return SpringContextUtils.getBean(DataBaseConfig.class);
21+
}
22+
}

0 commit comments

Comments
 (0)