#shared-memory #store #shm #inter-process #data-file #ramfs

shmap

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

11 releases

0.4.5 Dec 23, 2023
0.4.4 Aug 31, 2023
0.4.3 May 23, 2023
0.4.2 Jan 6, 2023
0.1.0 Apr 29, 2022

#245 in Concurrency

Download history 5/week @ 2024-02-23 3/week @ 2024-03-01 248/week @ 2024-03-08 25/week @ 2024-03-15 6/week @ 2024-03-29

254 downloads per month

MIT/Apache

35KB
786 lines

Shmap

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

Features

  • Items are stored in the unix 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(())
}

Dependencies

~3–11MB
~90K SLoC