| Crates.io | redish |
| lib.rs | redish |
| version | 0.5.1 |
| created_at | 2025-07-09 16:06:50.461739+00 |
| updated_at | 2025-11-05 14:30:10.731543+00 |
| description | A lightweight in-memory key-value database |
| homepage | https://github.com/swapper9/redish |
| repository | https://github.com/swapper9/redish |
| max_upload_size | |
| id | 1745068 |
| size | 249,599 |
A lightweight in-memory key-value storage DB created based on LSM Tree.
Default settings are:
use std::time::Duration;
use redish::tree::Tree;
use bincode::{Decode, Encode};
#[derive(Debug, Encode, Decode, Clone)]
struct User {
user_id: u64,
username: String,
}
let user = User {user_id: 3, username: "JohnDoe2020".to_string()};
// to use default path for db
let mut tree = Tree::load()?;
// or specified path
let mut tree2 = Tree::load_with_path("/path/to/db/with_file_name")?;
tree.put(b"key1".to_string().into_bytes(), "value".to_string().into_bytes())?;
tree.put_with_ttl("key2".to_string().into_bytes(), "value".to_string().into_bytes(), Some(Duration::from_secs(60)))?;
// type-friendly usage with turbo-fish
tree.put_typed::<User>("key3", &user)?;
assert_eq!(user.username, tree.get_typed::<User>("key3"));
let tree = Tree::load_with_settings(
TreeSettingsBuilder::new()
.db_path("./my_db")
.mem_table_max_size(20000)
.index_cache(true)
.value_cache(true)
.compressor(CompressionConfig::best())
.build()
)?;
let tx_id1 = tree.begin_transaction()?;
let tx_id2 = tree.begin_transaction()?;
tree.put_tx(tx_id1, b"key1".to_vec(), b"JohnDoe".to_vec(), None)?;
tree.put_tx(tx_id2, b"key_to_rollback".to_vec(), b"NotJohnDoe".to_vec(), None)?;
tree.commit_transaction(tx_id1)?;
tree.rollback_transaction(tx_id2)?;