Copyright (c) 2015 Benoît Chesneau.
Version: 0.1.0.
memdb is K/V store built on top of ETS. memdb compared to ETS provides concurrent access to the database using MVCC allowing multiple reader to read concurrently a consitent view of the database without locking.
All writes are serialized for now.
A MemDB'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 database if needed.
Full doc is available in the memdb
module.
'''
Db = memdb:open(Name).
Storing a value associated to a key using memdb:put/3
:
Key = <<"a">>,
Value = 1,
ok = memdb:put(Key, Value, Db).
Use the memdb:get/2
function to retrieve a value.
Value = memdb:get(Key, Db).
Value should be 1
Note: you can use
memdb:contains/2
.
Use memdb:delete/2
to delete a value:
ok = memdb:clear(Ke, Dby).
Using memdb:write_batch/2
you can write and delete multiple values in one
pass:
ok = memdb:write_batch([{put, <<"a">>, 1},
lput, <<"b">>, 2},
{put, <<"c">>, 3}], Db),
ok = memdb:write_batch([{put, <<"d">>, 4},
{delete, <<"b">>},
{put, <<"e">>, 5}], Db).
Use memdb:fold/4
to retrieve multiples K/Vs
Close a storage using memdb:close/1
:
memdb:close(Engine)
$ make
memdb |