2个版本
0.4.0-alpha.5 | 2023年3月6日 |
---|---|
0.4.0-alpha.4 | 2023年2月6日 |
0.4.0-alpha.2 |
|
#44 在 #key-value-database
被 3 crates 使用
60KB
981 行
Basteh
注意 主分支包含许多破坏性变更,请切换到v0.3分支以获取发布版本。
Basteh(之前为actix-storage)是一些键值存储的类型擦除包装,以提供通用操作。
安装
Basteh旨在与实现crate之一一起使用,例如
# Cargo.toml
[dependencies]
basteh = "0.4.0-alpha.5"
basteh-memory = "0.4.0-alpha.5"
用法
选择后端后
use basteh::{Basteh, BastehError};
use basteh_memory::MemoryBackend;
async fn handler() -> Result<String, BastehError> {
// Intialize the implementer according to its docs
let store = MemoryBackend::start_default();
// Give it to the Storage struct
let basteh = Basteh::build().store(store).finish();
// Set a key, value can be stringy, bytes or numbers
basteh.set("key", "value").await;
// And make it expire after 5 seconds
basteh.expire("key", Duration::from_secs(5)).await;
// Or just do both in one command(usually faster)
basteh.set_expiring("key", "value", Duration::from_secs(5)).await;
basteh.get::<String>("key").await
}
实现
还有一个基于sled的实现,但由于sled的情况,它尚未发布到crates.io
basteh是什么意思?
单词 basteh
是波斯语中的“盒子/包装”,就这么简单!听起来像英语中的其他单词吗?当然!但我很擅长命名软件包,另一个选择是 testorage
,类似于类型擦除存储...所以,basteh
很酷。
用例
在开发应用程序时围绕kv存储的主要想法来自我对django框架的喜爱以及它是如何使你的生活更轻松的。在django中有一个缓存框架,它就是这样做的!Basteh更加全面,它不仅用于缓存,还用于持久值,这就是为什么总会有一些持久实现的原因。
虽然它设计用于处理小型、主要是临时数据,但我没有计划使其在其他工作流程中效率降低,并且始终欢迎pull requests。
以下情况下很有用
- 你不知道以后需要哪种键值数据库。
- 在开发过程中无法承担某些数据库的长时间编译。
- 内存存储编译速度相当快
- 您正在编写一个扩展库,需要支持多个存储后端。
示例
在 examples
文件夹中有许多示例,虽然非常基础,但可以给您一些启示。
许可证
本项目可根据您的选择采用以下任一许可证:
- Apache许可证,版本2.0,(LICENSE-APACHE)
- MIT许可证 (LICENSE-MIT)
任选其一。
依赖项
约0.5-2.1MB
约41K SLoC