rocksredis 是redis内存数据库的增强版,采用rocksdb嵌入式数据库引擎作为redis的持久化数据管理。
redis 的高性能已经成为缓存数据管理的首选, redis的持久化有两种方式RDB和AOF一个是周期性持久化、一个是以日志模式写入 ,随着文件的增大redis的读写性能会降低,因此,redis只能作为一定数据量的缓存数据库管理。
rocksdb 为快速而又低延迟的存储设备(例如闪存或者高速硬盘)而特殊优化处理。 RocksDB将最大限度的发挥闪存和RAM的高度率读写性能。rocksdb在批量batchwrite处理上性能优越,因此需要在rocksredis‘冷热’数据分离的基础上增加数据的缓存机制以保证rocksdb的batchwrite处理。
rocksredis 采用magnet作为中间件实现磁性缓存和持久层的连接和管理,数据流先通过redis的缓存和管理下来,在通过magnet的数据处理线程池将缓存数据批量写入rocksdb.
rocksredis ,可以支持10万以上个keydb,每个keydb可以存储1亿条以上数据,单机版的rocksredis可以支持10万亿以上的数据存储.
应用场景,rocksredis非常适合以下场景:
目录
|--libs
|--bin
|--redis.conf
|--runstart.sh
libs 目录为rocksredis运行依赖库
bin 目录为rocksredis执行程序
redis.conf 配置文件
runstart.sh 执行脚本
redis.conf 配置说明
########################### ROCKSREDIS CONFIG #######################
#Select a DB of redis as the pipeline of rocksreids db
#If redis is a cluster, DB is 0 by default
#If it is single, you can choose from 0 to 15
#If this option is commented out, the rocksredis database will be closed,
#and rocksredis will be used as the cache database.
rocksredis_db_select 15
#Rockredis Data storage path
#Default path is /data
rocksredis_db_dir /home/data
#Batch data write length size,It can be adjusted according to the write frequency.
#The default size is 2000
rocks_write_batch_size 2000
#Set the size of a single memtable. Once the memtable exceeds this size,
#it will be marked as immutable and a new one will be created.
#The default size is 64MB ,64*1024*1024
write_buffer_size 67108864
#Set the maximum number of memtables, active and non modifiable.
#If the active memtable is filled, then the total number of memtables is greater than max_ write_ buffer_ Number,
#we will stall subsequent writes. Occurs when the drop process is slower than the write speed.
#The default size is 3
max_write_buffer_number 3
#Is the number of disk dropping concurrent. Usually, a setting of 1 is enough
#Here, the default size is 4
max_background_flushes 4
#Is the maximum number of threads for background compression.
#The default is 1, but in order to make full use of CPU and storage,
#you may want to increase the number of cores close to the system.
#The default size here is 8
max_background_compactions 8
#Background execution thread of data batch disk dropping processing
#The default value is 10, which can be configured according to the actual needs
batch_write_background_threadpools 10
#选择redis的一个db作为rocksdb的持久化管道,单机版的redis默认db0~db15,缺省状态下为15;
#其余 db可以作为redis的缓存正常使用;弱不希望rocksdb作持久化则可以设置rocksredis_db_select为-1;
rocksredis_db_select 15
#rocksredis 持久化数据库的路径设置
rocksredis_db_dir /home/data
#rocksredis 批量持久化的batchsize
rocks_write_batch_size 2000
#rocksdb 的写缓存buffer size
write_buffer_size 67108864
#rocksdb 的写缓存buffer 数量
max_write_buffer_number 3
#rocksdb 后台刷新线程数
max_background_flushes 4
#rocksdb 后台合并线程数
max_background_compactions 8
#rocksdb 后台批量持久化的线程池数
batch_write_background_threadpools 10
运行
执行运行脚本 ./runstart.sh
6.0.8 为redis的基础版本
06 为rocksredis的版本
Rocksredis 完全兼容redis的驱动和操作方式,rocksredis支持的操作指令,
num | command |
---|---|
1 | [HDEL key field1 field2] 删除一个或多个哈希表字段 |
2 | HEXISTS key field 查看哈希表 key 中,指定的字段是否存在。 |
3 | HGET key field 获取存储在哈希表中指定字段的值。 |
4 | HGETALL key 获取在哈希表中指定 key 的所有字段和值 |
5 | HKEYS key 获取所有哈希表中的字段 |
6 | HLEN key 获取哈希表中字段的数量 |
7 | [HMGET key field1 field2] 获取所有给定字段的值 |
8 | [HMSET key field1 value1 field2 value2 ] 同时将多个 field-value (域-值)对设置到哈希表 key 中。 |
9 | HSET key field value 将哈希表 key 中的字段 field 的值设为 value 。 |
10 | HSETNX key field value 只有在字段 field 不存在时,设置哈希表字段的值。 |
11 | HVALS key 获取哈希表中所有值。 |
12 | HSCAN key cursor [MATCH pattern] [COUNT count] 迭代哈希表中的键值对。 |
13 | DEL 命令用于删除已存在的键 |
14 | Strlen 命令用于获取指定 key 所储存的字符串值的长度 |
15 | Scan 命令用于迭代数据库中的数据库键 |
16 | Type 命令用于返回 key 所储存的值的类型 |
17 | Sadd 命令将一个或多个成员元素加入到集合中,已经存在于集合的成员元素将被忽略 |
18 | Scard 命令返回集合中元素的数量 |
19 | Sismember 命令判断成员元素是否是集合的成员 |
20 | Smembers 命令返回集合中的所有的成员。 不存在的集合 key 被视为空集合 |
21 | Spop 命令用于移除集合中的指定 key 的一个或多个随机元素,移除后会返回移除的元素 |
22 | Sscan 命令用于迭代集合中键的元素 |
23 | Srem 命令用于移除集合中的一个或多个成员元素 |
24 | SET 命令用于设置给定 key 的值。如果 key 已经存储其他值, SET 就覆写旧值,且无视类型 |
25 | Get 命令用于获取指定 key 的值。如果 key 不存在,返回 nil 。如果key 储存的值不是字符串类型,返回一个错误 |
JAVA
引入redis驱动到pom
<!-- redis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
PYTHON
pip install redis==2.10.6
C/C++
引入库hiredis.a
cpu: 2核
内存:8G
二手机械磁盘:500G,实际检测与硬盘性能有关
测试一、Hash 存储,hsetnx()
Items:10000,Data:1Kbyte,Type:String
start:Mon Apr 26 13:36:21 CST 2021
耗时: 28.324 (s)
Items:50000,Data:1Kbyte,Type:String
start:Mon Apr 26 13:36:21 CST 2021
耗时: 65.102s)
Items:100000,Data:1Kbyte,Type:String
start:Mon Apr 26 15:09:03 CST 2021
耗时:172.914 (s)
测试二、Hash 存储,hsetnx()
Items:10000,Data:10Kbyte,Type:String
start:Mon Apr 26 15:26:14 CST 2021
耗时: 27.288(s)
Items:50000,Data:10Kbyte,Type:String
start:Mon Apr 26 16:19:51 CST 2021
耗时: 137.374(s)
Items:100000,Data:10Kbyte,Type:String
start:Mon Apr 26 16:23:47 CST 2021
耗时: 275.583(s)
Read Items:10000,Data:10KB,Type:String
start:Mon Apr 26 16:42:41 CST 2021
耗时: 8.567(s)
Read Items:100000,Data:10KB,Type:String
start:Mon Apr 26 16:43:32 CST 2021
耗时: 85.449(s)
gitee
github
其他
rocksredis 基础评测阶段已完成,在Rocksiot物联云平台、设备智能管理平台、预测性维护等平台上得到广泛应用,欢迎大家参与技术合作与交流.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。