Skip to content

lsferreira42/nadb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NADB - Not A Database

A simple, thread-safe, zero external dependencies key-value store with asynchronous memory buffering capabilities and disk persistence.

🚨 This project is educational and not intended for production use. 🚨

Features

  • Thread-safe operations for setting, getting, and deleting key-value pairs.
  • In-memory buffering of key-value pairs with asynchronous flushing to disk.
  • Periodic flushing of the buffer to disk to ensure data integrity.
  • Manual flushing capability for immediate persistence.
  • Namespace and database separation for organized data storage.
  • Simple usage and minimal setup required.

Installation

pip install nadb

Quickstart

Here's a basic example of how to use NADB:

from nadb import KeyValueStore, KeyValueSync

# Create a KeyValueStore instance

data_folder_path = './data'
db_name = 'db1'
buffer_size_mb = 1  # 1 MB
flush_interval_seconds = 60  # 1 minute
namespace = 'namespace1'

# Initialize the KeyValueSync for asynchronous flushing
kv_sync = KeyValueSync(flush_interval_seconds)

# Initialize the KeyValueStore
kv_store = KeyValueStore(data_folder_path, db_name, buffer_size_mb, namespace, kv_sync)

# Set some key-value pairs
kv_store.set('key1', 'value1')
kv_store.set('key2', 'value2')
kv_store.set('key3', 'value3')

# Get a value
value1 = kv_store.get('key1')  # Returns 'value1'

# Delete a key-value pair
kv_store.delete('key1')

# Manual flush (optional, as flushing occurs automatically based on buffer size and time interval)
kv_store.flush()

# Retrieve the status of all KeyValueStore instances
status = kv_sync.status()  # Returns a list of dictionaries with information about each KeyValueStore instance

# Stop accepting new KeyValueStore registrations, sync remaining ones, and exit
kv_sync.sync_exit()

About

Not a database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages