redisql 试用
redisql 是一个redis 模块,可以让redis 支持sql 查询,基于rust编写
具有以下特性
- 快速,每秒130k的插入
- 使用标准sql
- 容易操作,基于redis,使用标准的redis 二进制文件(主要还是4.0 的的模块机制)
- 使用简单,可以使用基于redis 的任务语言绑定
- stream cache 查询数据,可以基于redis 的stream 进行扩展
- 完整的json 支持
- 全文检索支持
使用场景
- 存储暂态数据
- 做为主数据库(通过aof 以及rdb进行持久化)
简单使用
推荐的是redis> 5.0 ,为了简单我使用的是docker 运行,但是因为官方docker 镜像有一个遥测服务,
但是这个服务网络不通,所以注释了,源码参考redisql
- docker-compose 文件
version: "3"
services:
db:
image: dalongrong/redisql
ports:
- "6379:6379"
- 启动
docker-compose up -d
- 效果
Attaching to redisql_db_1
db_1 | 1:C 01 Aug 2019 11:49:56.140 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
db_1 | 1:C 01 Aug 2019 11:49:56.140 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
db_1 | 1:C 01 Aug 2019 11:49:56.140 # Configuration loaded
db_1 | 1:M 01 Aug 2019 11:49:56.142 * Running mode=standalone, port=6379.
db_1 | 1:M 01 Aug 2019 11:49:56.142 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
db_1 | 1:M 01 Aug 2019 11:49:56.142 # Server initialized
db_1 | 1:M 01 Aug 2019 11:49:56.142 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
db_1 | 1:M 01 Aug 2019 11:49:56.142 * Module 'rediSQL' loaded from /usr/local/lib/libredis_sql.so
db_1 | 1:M 01 Aug 2019 11:49:56.142 * Ready to accept connections
- 基本数据库操作
redis-cli
127.0.0.1:6379> REDISQL.CREATE_DB DB
OK
127.0.0.1:6379> REDISQL.EXEC DB "CREATE TABLE foo(A INT, B TEXT);"
1) DONE
2) (integer) 0
127.0.0.1:6379> REDISQL.EXEC DB "INSERT INTO foo VALUES(3, 'bar');"
1) DONE
2) (integer) 1
127.0.0.1:6379> REDISQL.EXEC DB "SELECT * FROM foo;"
1) 1) (integer) 3
2) "bar"
127.0.0.1:6379> REDISQL.EXEC DB "CREATE TABLE baz(C INT, B TEXT);"
1) DONE
2) (integer) 0
127.0.0.1:6379> REDISQL.EXEC DB "INSERT INTO baz VALUES(3, 'aaa');"
1) DONE
2) (integer) 1
127.0.0.1:6379> REDISQL.EXEC DB "INSERT INTO baz VALUES(3, 'bbb');"
1) DONE
2) (integer) 1
127.0.0.1:6379> REDISQL.EXEC DB "INSERT INTO baz VALUES(3, 'ccc');"
1) DONE
2) (integer) 1
127.0.0.1:6379> REDISQL.EXEC DB "SELECT * FROM foo, baz WHERE foo.A = baz.C;"
1) 1) (integer) 3
2) "bar"
3) (integer) 3
4) "aaa"
2) 1) (integer) 3
2) "bar"
3) (integer) 3
4) "bbb"
3) 1) (integer) 3
2) "bar"
3) (integer) 3
4) "ccc"
127.0.0.1:6379>
说明
官方文档也提供了各种语言绑定的使用,还是很不错的