2个版本

0.4.0-alpha.52023年3月6日
0.4.0-alpha.42023年2月6日
0.4.0-alpha.2 2023年2月1日

#44#key-value-database


3 crates 使用

MIT/Apache

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
}

实现

basteh-memory docs.rs docs

basteh-redb docs.rs docs

basteh-redis docs.rs docs

还有一个基于sled的实现,但由于sled的情况,它尚未发布到crates.io

basteh是什么意思?

单词 basteh 是波斯语中的“盒子/包装”,就这么简单!听起来像英语中的其他单词吗?当然!但我很擅长命名软件包,另一个选择是 testorage,类似于类型擦除存储...所以,basteh 很酷。

用例

在开发应用程序时围绕kv存储的主要想法来自我对django框架的喜爱以及它是如何使你的生活更轻松的。在django中有一个缓存框架,它就是这样做的!Basteh更加全面,它不仅用于缓存,还用于持久值,这就是为什么总会有一些持久实现的原因。

虽然它设计用于处理小型、主要是临时数据,但我没有计划使其在其他工作流程中效率降低,并且始终欢迎pull requests。

以下情况下很有用

  1. 你不知道以后需要哪种键值数据库。
  2. 在开发过程中无法承担某些数据库的长时间编译。
    • 内存存储编译速度相当快
  3. 您正在编写一个扩展库,需要支持多个存储后端。

示例

examples 文件夹中有许多示例,虽然非常基础,但可以给您一些启示。

许可证

本项目可根据您的选择采用以下任一许可证:

任选其一。

依赖项

约0.5-2.1MB
约41K SLoC