0blivi0n's binary protocol client
Using rebar:
{deps, [
{pencil, ".*", {git, "https://github.com/0blivi0n/pencil.git", "master"}}
]}.
PENCIL provides two parameters to specify the Oblivion's server IP and port.
To change the default values, set value of the properties "oblivion_server" and "oblivion_port" on your config file.
[
{pencil, [
{oblivion_server, "127.0.0.1"},
{oblivion_port, 12521}
]
}
].
PENCIL depends on three apps MEC, jsondoc and poolboy, the 3 apps must be running before starting PENCIL.
1> application:start(mec).
ok
2> application:start(poolboy).
ok
3> application:start(jsondoc).
ok
4> application:start(pencil).
ok
The module pencil
provides the following functions to interact with the 0blivi0n's server.
put(Cache :: binary(), Key :: binary(), Value :: jsondoc:jsondoc()) ->
{error, Reason :: any()} | {ok, Version :: integer()}.
put(Cache :: binary(), Key :: binary(), Value :: jsondoc:jsondoc(), Version :: integer()) ->
{error, Reason :: any()} | {ok, NewVersion :: integer()}.
get(Cache :: binary(), Key :: binary()) ->
{error, Reason :: any()} | {ok, Value :: jsondoc:jsondoc(), Version :: integer()}.
delete(Cache :: binary(), Key :: binary()) ->
{error, Reason :: any()} | ok.
delete(Cache :: binary(), Key :: binary(), Version :: integer()) ->
{error, Reason :: any()} | ok.
version(Cache :: binary(), Key :: binary()) ->
{error, Reason :: any()} | {ok, Version :: integer()}.
size(Cache :: binary()) ->
{error, Reason :: any()} | {ok, Size :: integer()}.
flush(Cache :: binary()) ->
{error, Reason :: any()} | ok.
caches() ->
{error, Reason :: any()} | {ok, Caches :: list()}.
keys(Cache :: binary()) ->
{error, Reason :: any()} | {ok, Keys :: list()}.
5> pencil:caches().
{ok,[<<"test">>]}
6> pencil:put(<<"test">>, <<"jr">>, <<"Joaquim Rocha">>).
{ok,1447028787208699}
7> pencil:put(<<"test">>, <<"jr">>, <<"Joaquim JM Rocha">>, 1447028787208699).
{ok,1447028814375356}
8> pencil:put(<<"test">>, <<"array">>, [1, 3, true, <<"Text">>, 123.4]).
{ok,1447028874693208}
9> pencil:get(<<"test">>, <<"jr">>).
{ok,<<"Joaquim JR Rocha">>,1447028814375356}
10> pencil:version(<<"test">>, <<"array">>).
{ok,1447028874693208}
11> pencil:keys(<<"test">>).
{ok,[<<"array">>,<<"jr">>]}
12> pencil:delete(<<"test">>, <<"jr">>).
ok
13> pencil:delete(<<"test">>, <<"array">>, 1447028874693208).
ok
14> pencil:flush(<<"test">>).
ok