Skip to content

Latest commit

 

History

History
129 lines (86 loc) · 3.15 KB

README.md

File metadata and controls

129 lines (86 loc) · 3.15 KB

ets-kv

Build Status Erlang Versions Tags

A simple in-memory K/V store with MVCC semantics for Erlang/BEAM languages

Contents

Overview

The ets-kv project (originally "memdb") offers BEAM languages a simple K/V store built on top of ETS. In addition to ETS features and capabilities, ets-kv provides concurrent access to the store using MVCC, allowing multiple clients to read the store concurrently, getting a consitent view of the store without locking.

All writes are serialized for now.

Note that ets-kv's memory consumption increases monotonically, even if keys are deleted or values are updated. Compaction can be triggered manually or automatically using the auto-vacuum. A full snapshot can be stored or copied in another store if needed.

Build

$ rebar3 compile

Usage

In the directory of a clone of this repo, start up an Erlang shell:

$ rebar3 shell

Create a Store

Name = mystor.
Store = etskv:open(Name).

Add a value

Add a value associated with a key using etskv:put/3:

Key = <<"a">>,
Value = 1,
ok =  etskv:put(Key, Value, Store).

Retrieve a value

Use the etskv:get/2 function to retrieve a value.

Value = etskv:get(Key, Store).

Value should be 1. Note that you can use etskv:contains/2 to check ahead of time:

etskv:contains(Key, Store).

Delete a value

Use etskv:delete/2 to delete a value:

ok = etskv:delete(Key, Store).

Working with Multiple Values

Storing

Using etskv:batch/2 you can write and delete multiple values in one pass:

ok =  etskv:batch([{put, <<"a">>, 1},
                   {put, <<"b">>, 2},
                   {put, <<"c">>, 3}], Store),

ok =  etskv:batch([{put, <<"d">>, 4},
                   {del, <<"b">>},
                   {put, <<"e">>, 5}], Store).

Retrieving

Use etskv:fold/4 to retrieve multiples K/Vs

Close the Store

Close a storage using etskv:close/1:

etskv:close(Store)

License

Copyright © 2015 Benoît Chesneau
Copyright © 2024 Duncan McGreggor

Distributed under the Mozilla Public License Version 2.0.