storages

Collection of key-value storages adapters for Golang

This project is maintained by reddec

In-Memory

API docs

Based on hashmap and RWLock in-memory storage. Values and keys are copied before put

For namespaces used Go sync.Map.

URL initialization

Do not forget to import package!

memory://

Usage

storage := memstorage.New()

Close() is not required, however it is implemented as NOP.

Features

Batch writing

Support BatchedStorage interface.

It allows to cache Put operations and execute them in one batch. In general case it may increase write throughput.

Batch implements Writer interface.

Example:

batchWriter := storage.Batch()

batchWriter.Put([]byte("key1"),[]byte("value1")
batchWriter.Put([]byte("key2"),[]byte("value2")
//...
batchWriter.Put([]byte("keyN"),[]byte("valueN")

// flush/write batch to storage
batchWriter.Close() 

Namespaces

Support NamespacedStorage interface.

It allows make nested sub-storages with independent key space.

Example:

aliceStorage := storage.Namespace([]byte("alice"))
bobStorage := storage.Namespace([]byte("bob"))

Clearable

Support Clearable interface.

Allows clean all internal information by one operation.

Example:

err := storage.Clean()
if err != nil {
    panic("failed to clean")
}