Git Product home page Git Product logo

fdb-erlang's Introduction

fdb-erlang

Erlang bindings for FoundationDB.

This is still very early alpha.

Prerequisites

Developed and tested on ubuntu only (for now). It requires you to have Erlang and the FoundationDB client libraries installed.

Due to the way enif_send is implemented in Erlang NIFs, your system needs to run with at least 2 core's.

Update

Apparently you can also work around this by using erl -smp enable.

Big thanks to Valery Meleshkin for the tip!

Compilation and testing

git clone [email protected]:HappyPancake/fdb-erlang.git
cd fdb-erlang
chmod u+x rebar
./rebar get-deps compile eunit -v

(venv) jiangphs-mbp-2:fdb-erlang jiangph$  ./rebar get-deps compile eunit -v
==> fdb-erlang (get-deps)
==> fdb-erlang (compile)
==> fdb-erlang (eunit)
======================== EUnit ========================
module 'directory'
module 'maybe'
module 'gen_fdb'
module 'subspace'
subspace_test: basic_test (module 'subspace_test')...[0.102 s] ok
module 'tuple'
module 'tuple_test'
  tuple_test: pack_test...ok
  tuple_test: pack_order_test...ok
  tuple_test: unpack_test...ok
  [done in 0.009 s]
module 'fdb'
module 'fdb_nif'
module 'stress_test'
module 'directory_test'
module 'fdb_test'
  fdb_test: hello_world_test...[0.038 s] ok
  fdb_test: transaction_test...[0.045 s] ok
  fdb_test: range_test...[0.017 s] ok
  [done in 0.109 s]
fdb_nif_test: store_and_retrieve_test (module 'fdb_nif_test')...[0.001 s] ok
=======================================================
  All 8 tests passed.

Example usage

This is the simplest possible usage:

tojans@ubuntu:/tmp/fdb-erlang$ erl -pa ebin
Erlang R16B02 (erts-5.10.3) [source-5d89ddd] [64-bit] [async-threads:10] [kernel-poll:false]

Eshell V5.10.3  (abort with ^G)
1> fdb:init().
ok
2> fdb:api_version(100).
0
3> DB = fdb:open().
{db,<<>>}
4> fdb:get(DB,<<"Hello">>).
not_found
5> fdb:set(DB,<<"Hello">>,<<"World">>).
ok
6> fdb:get(DB,<<"Hello">>).            
<<"World">>
7> fdb:get(DB,<<"Hello2">>,some_default_value).
some_default_value
8> fdb:clear(DB,<<"Hello">>).
ok
9> fdb:get(DB,<<"Hello">>).
not_found
10>

If you want to have a transaction, you need to invoke code like this:

10> fdb:transact(DB, fun(Tx) ->                         
10>   fdb:set(Tx,<<"Hello">>,<<"World">>),            
10>   fdb:set(Tx,<<"xyz">>,<<"abc">>),                
10>   [fdb:get(Tx,<<"xyz">>)|fdb:get(Tx,<<"Hello">>)]   
10> end).
[<<"abc">>|<<"World">>]
11>

It will invoke the lambda multiple times until the whole action succeeds or it seems unreasonable to try any longer. If the code in the lambda crashes, the transaction will be rolled back.

fdb-erlang's People

Contributors

jiangphcn avatar ptomasroos avatar tojans avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.