小Redis:开源一款迷你C++17 KV内存型数据库

A KV high-performance mini-database based on memory and C++17

This project is inspired by Redis source code.
部分模仿Redis源码。
https://github.com/ZYunfeii/MiniKV

Command line tools

Developed command line tool kvctl.
value type:string

yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key qjx --operate set --value world --ip 43.143.229.22
+--------+
| Status |
+--------+
| OK     |
+--------+
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key qjx --operate get --ip 43.143.229.22
+-------+
| Value |
+-------+
| world |
+-------+

value type:list

yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate set --value hello --encoding list --ip 43.143.229.22
+--------+
| Status |
+--------+
| OK     |
+--------+
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate set --value world --encoding list --ip 43.143.229.22
+--------+
| Status |
+--------+
| OK     |
+--------+
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate get --ip 43.143.229.22
+-------+
| Value |
+-------+
| hello |
| world |
+-------+

search key using regex:

yunfei@ubuntu:~/MiniKV/build$ ./kvctl --keyRex .* --operate findkey --ip 43.143.229.22
+--------+
| Key    |
+--------+
| zyf    |
| yunfei |
| qjx    |
+--------+

build

Dependencies: grpc, protobuf, gflags
In the project dir, do:

cd build && cmake .. && make

then you can get kvserver and kvclient.

run

./kvserver

Persistent data frame format

小Redis:开源一款迷你C++17 KV内存型数据库_第1张图片

About

  • 基于gRPC实现客户端与服务端通信,基于读写锁实现并发安全;客户端支持键的增删改查;

  • 支持数据快照,后台线程定时持久化,基于自定义数据帧格式;服务启动自动读取快照;

  • 底层存储结构模仿redis哈希表设计,拉链法解决哈希冲突,智能指针实现内存自动管理;

  • 模仿redis基于过期哈希表实现过期Key,通过惰性删除实现过期键的清理;

  • 模仿redis双哈希表设计,后台线程定期计算负载因子后实现渐进rehash;

  • 基于gflags开发命令行工具kvctl,调用client的接口实现KV的增删改查;

你可能感兴趣的:(C++,计算机网络,Linux,redis,数据库,哈希算法)