-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
新增 RediSQL Demo,支持 Redis 零代码 CRUD,感谢 cloudAndMonkey 的贡献 #31
- Loading branch information
Showing
22 changed files
with
3,990 additions
and
0 deletions.
There are no files selected for viewing
154 changes: 154 additions & 0 deletions
154
APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
# APIJSONDemo | ||
|
||
## 支持多数据源-rediSQL | ||
|
||
redis table 表名规范: REDIS_TABLE_* <br/> | ||
开发人员可自行控制 <br/> | ||
JedisBuildData <br/> | ||
public static final String REDIS_TABLE_KEY = "REDIS_TABLE_"; // rediSql table prefix <br/> | ||
|
||
Access、Request配置 访问操作权限 <br/> | ||
|
||
rediSQL安装使用 <br/> | ||
https://github.com/RedBeardLab/rediSQL | ||
|
||
官方docker安装 <br/> | ||
docker pull dalongrong/redisql | ||
docker run -itd --name redisql -p 6399:6379 dalongrong/redisql | ||
|
||
rediSQL注意事项 <br/> | ||
rediSQL免费版有后遥控制,每个小时会发送 redist info 统计信息<br/> | ||
<img width="1000" alt="image" src="https://user-images.githubusercontent.com/12228225/219613765-e8d4d963-035b-4352-9552-1ce3a14093e4.png"> | ||
|
||
可以配host ,弄一个nginx 本地代理 解决,或者 项目自己重新打包<br/> | ||
|
||
rediSQL java:<br/> | ||
https://github.com/RedBeardLab/JRediSQL<br/> | ||
https://www.youtube.com/watch?v=YRusC-AIq_g | ||
|
||
本示例 用 redis cluster rediSQL, 具体redis集群模式, 开发人员自行控制<br/> | ||
将 libredis_sql.so 导入redis.config<br/> | ||
--loadmodule /etc/redis/libredis_sql.so<br/> | ||
rediSQL 创建数据库表命令 <br/> | ||
``` | ||
REDISQL.EXEC DB "CREATE TABLE REDIS_TABLE_A(id TEXT, A INT, B TEXT, C TEXT, userId TEXT);" | ||
REDISQL.EXEC DB "INSERT INTO REDIS_TABLE_A(id,A,B,C,userId) VALUES('1', 3, '1c', 'bar','1');" | ||
REDISQL.EXEC DB "SELECT * FROM REDIS_TABLE_A;" | ||
REDISQL.EXEC DB "drop table REDIS_TABLE_A;" | ||
``` | ||
|
||
测试用例<br/> | ||
``` | ||
{ | ||
"@datasource": "redisCluster", | ||
"REDIS_TABLE_A":{ | ||
"A": 1, | ||
"B": "B", | ||
"C": "C" | ||
}, | ||
"tag": "REDIS_TABLE_A", | ||
"@explain": true, | ||
"format": true | ||
} | ||
{ | ||
"REDIS_TABLE_A[]": [ | ||
{ | ||
"A": 5, | ||
"B": "5B", | ||
"C": "5C" | ||
}, | ||
{ | ||
"A": 6, | ||
"B": "6B", | ||
"C": "6C" | ||
}, | ||
{ | ||
"A": 7, | ||
"B": "7B", | ||
"C": "7C" | ||
} | ||
], | ||
"tag": "REDIS_TABLE_A[]", | ||
"@datasource": "redisCluster", | ||
"@explain": true, | ||
"format": true | ||
} | ||
{ | ||
"@datasource": "redisCluster", | ||
"REDIS_TABLE_A": { | ||
"id": "f2621698-99fa-4698-9fb0-8c7b585da403", | ||
"A": 1, | ||
"B": "1B" | ||
}, | ||
"tag": "REDIS_TABLE_A", | ||
"@explain": true, | ||
"format": true | ||
} | ||
Request 表配置 | ||
{"REDIS_TABLE_A[]": [{"MUST": "A,B", "REFUSE": "id"}], "INSERT": {"@role": "OWNER,ADMIN","@combine": "A | B"}} | ||
{ | ||
"@datasource": "redisCluster", | ||
"REDIS_TABLE_A": { | ||
"A": 1, | ||
"B": "1B", | ||
"C": "1-1-1C" | ||
}, | ||
"tag": "REDIS_TABLE_A", | ||
"@explain": true, | ||
"format": true | ||
} | ||
{ | ||
"@datasource": "redisCluster", | ||
"REDIS_TABLE_A:a": { | ||
"@column":"a,b,c", | ||
"b$": "7B%" | ||
}, | ||
"@explain": true, | ||
"format": true | ||
} | ||
{ | ||
"@datasource": "redisCluster", | ||
"REDIS_TABLE_A:a[]": { | ||
"REDIS_TABLE_A": { | ||
"@column":"a,b,c" | ||
//"b$": "1%" | ||
}, | ||
"page":0, | ||
"count":3, | ||
"query": 2 | ||
}, | ||
"total@": "/REDIS_TABLE_A:a[]/total", | ||
"@explain": true, | ||
"format": true | ||
} | ||
{ | ||
"@datasource": "redisCluster", | ||
"REDIS_TABLE_A": { | ||
"id": "f2621698-99fa-4698-9fb0-8c7b585da403" | ||
}, | ||
"tag": "REDIS_TABLE_A", | ||
"@explain": true, | ||
"format": true | ||
} | ||
{ | ||
"@datasource": "redisCluster", | ||
"REDIS_TABLE_A:a": { | ||
"id{}": ["1","eb3dd7c9-bab6-410c-b70a-cbbc3bd12896", "c83b3cfa-034e-4a9e-b2cf-83520db1ce05"] | ||
}, | ||
"tag": "REDIS_TABLE_A[]", | ||
"@explain": true, | ||
"format": true | ||
} | ||
``` |
196 changes: 196 additions & 0 deletions
196
APIJSON-Java-Server/APIJSONDemo-MultiDataSource-RediSQL/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.5.13</version> | ||
<!-- <relativePath>./pom.xml</relativePath>--> | ||
</parent> | ||
<groupId>apijson.demo</groupId> | ||
<artifactId>apijsondemo-multidatasource-rediSQL</artifactId> | ||
<version>6.0.0</version> | ||
|
||
<name>apijsondemo-multidatasource-rediSQL</name> | ||
<description>Demo project for testing APIJSON server based on SpringBoot</description> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<commons-lang3.version>3.12.0</commons-lang3.version> | ||
<druid.version>1.1.16</druid.version> | ||
<mybatisplus.version>3.5.1</mybatisplus.version> | ||
<mybatis-plus-support.version>2.3.3</mybatis-plus-support.version> | ||
<commons-collections4.version>4.4</commons-collections4.version> | ||
<commons.configuration.version>1.10</commons.configuration.version> | ||
<guava.version>30.1.1-jre</guava.version> | ||
<fastjson.version>1.2.72</fastjson.version> | ||
<hutool.version>4.1.1</hutool.version> | ||
<lombok.version>1.18.4</lombok.version> | ||
<commons-lang3.version>3.12.0</commons-lang3.version> | ||
<commons.io.version>2.5</commons.io.version> | ||
<commons.codec.version>1.10</commons.codec.version> | ||
<commons-collections4.version>4.4</commons-collections4.version> | ||
<commons.configuration.version>1.10</commons.configuration.version> | ||
<apijson.version>6.0.0</apijson.version> | ||
<mysql.version>8.0.31</mysql.version> | ||
<spring-context-support.version>5.3.18</spring-context-support.version> | ||
<spring-boot-configuration-processor.version>2.6.6</spring-boot-configuration-processor.version> | ||
<dynamic-datasource-spring-boot-starter.version>3.5.2</dynamic-datasource-spring-boot-starter.version> | ||
<jedis.version>3.7.1</jedis.version> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- 需要的 APIJSON 相关依赖 --> | ||
<dependency> | ||
<groupId>com.github.Tencent</groupId> | ||
<artifactId>APIJSON</artifactId> | ||
<version>${apijson.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.APIJSON</groupId> | ||
<artifactId>apijson-framework</artifactId> | ||
<version>${apijson.version}</version> | ||
</dependency> | ||
|
||
<!-- 需要用的数据库 JDBC 驱动 --> | ||
|
||
<!-- Oracle, SQLServer 等其它数据库的 JDBC 驱动,可以在这里加上 Maven 依赖或 libs 目录放 Jar 包并依赖 --> | ||
|
||
<!-- 需要用的 SpringBoot 框架,1.4.0 以上 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context-support</artifactId> | ||
<version>${spring-context-support.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-configuration-processor</artifactId> | ||
<version>${spring-boot-configuration-processor.version}</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba</groupId> | ||
<artifactId>druid-spring-boot-starter</artifactId> | ||
<version>${druid.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.baomidou</groupId> | ||
<artifactId>dynamic-datasource-spring-boot-starter</artifactId> | ||
<version>${dynamic-datasource-spring-boot-starter.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.baomidou</groupId> | ||
<artifactId>mybatis-plus-boot-starter</artifactId> | ||
<version>${mybatisplus.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>com.baomidou</groupId> | ||
<artifactId>mybatis-plus-generator</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.baomidou</groupId> | ||
<artifactId>mybatis-plus-support</artifactId> | ||
<version>${mybatis-plus-support.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-collections4</artifactId> | ||
<version>${commons-collections4.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>${mysql.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>${guava.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>${lombok.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>${commons.io.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-codec</groupId> | ||
<artifactId>commons-codec</artifactId> | ||
<version>${commons.codec.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-configuration</groupId> | ||
<artifactId>commons-configuration</artifactId> | ||
<version>${commons.configuration.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>redis.clients</groupId> | ||
<artifactId>jedis</artifactId> | ||
<version>${jedis.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<configuration> | ||
<fork>true</fork> | ||
<mainClass>apijson.demo.DemoApplication</mainClass> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<repositories> | ||
<!-- APIJSON 必须用到的托管平台 --> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
|
||
<repository> | ||
<id>spring-snapshots</id> | ||
<url>https://repo.spring.io/snapshot</url> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
<repository> | ||
<id>spring-milestones</id> | ||
<url>https://repo.spring.io/milestone</url> | ||
</repository> | ||
</repositories> | ||
|
||
</project> |
22 changes: 22 additions & 0 deletions
22
...Server/APIJSONDemo-MultiDataSource-RediSQL/src/main/java/apijson/demo/DataBaseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package apijson.demo; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class DataBaseConfig { | ||
private String primary; | ||
|
||
@Value("${spring.datasource.dynamic.primary}") | ||
public void setPrimary(String primary) { | ||
this.primary = primary; | ||
} | ||
|
||
public String getPrimary() { | ||
return primary; | ||
} | ||
|
||
public static DataBaseConfig getInstence() { | ||
return SpringContextUtils.getBean(DataBaseConfig.class); | ||
} | ||
} |
Oops, something went wrong.