shmap

Crates.ioshmap
lib.rsshmap
version0.4.7
sourcesrc
created_at2022-04-29 21:36:29.756028
updated_at2024-09-30 19:11:19.042778
descriptionA key-value store based on linux shared-memory files (shm) for persisting state across program restarts.
homepagehttps://github.com/BarbossHack/shmap
repositoryhttps://github.com/BarbossHack/shmap
max_upload_size
id577849
size36,879
BarbossHack (BarbossHack)

documentation

README

Shmap

A key-value store based on linux shared-memory files (shm) for persisting state across program restarts.

Features

  • Items are stored in the linux shared memory: it uses shm_open to create file in the ramdisk (/dev/shm), then they are mapped in memory with mmap.

  • Concurrent access to items it provided thanks to named-lock mutexes.

  • Value serialization can be made transparently with serde (bincode), so don't forget to use serde_bytes to enable optimized handling of &[u8] and Vec<u8> !

  • You can protect your data with AES256-GCM encryption.

  • You can add a TTL so that your items won't be available anymore after this timeout.

Example

use shmap::{Shmap, ShmapError};
use std::time::Duration;

fn main() -> Result<(), ShmapError> {
    let shmap = Shmap::new();

    shmap.insert("key", "value")?;
    let value = shmap.get("key")?;

    assert_eq!(Some("value".to_string()), value);

    // It is strongly advised to use TTL to avoid using too much RAM
    shmap.insert_with_ttl("key", "temporary_value", Duration::from_secs(60))?;

    Ok(())
}

Supported OS

Any POSIX linux where /dev/shm is mounted. MacOS and any BSD descendants are therefore not supported.

man shm_open(3)

The POSIX shared memory object implementation on Linux makes use of a dedicated tmpfs(5) filesystem that is normally mounted under /dev/shm.
Commit count: 52

cargo fmt