summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/permdb.erl26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/permdb.erl b/src/permdb.erl
index 16ba28a..461b8b3 100644
--- a/src/permdb.erl
+++ b/src/permdb.erl
@@ -6,7 +6,7 @@
-behaviour(gen_server).
-export([start_link/2, stop/1, init_module/0]).
--export([getvalue/2, addvalue/3, commit/1, commit/2]).
+-export([getvalue/2, addvalue/3, commit/1, commit/2, keyexists/2]).
%% gen_server callbacks.
-export([init/1, handle_call/3, terminate/2, handle_cast/2, handle_info/2,
@@ -23,9 +23,15 @@ addvalue_port_command(Port, Key, Value) ->
commit_port_command(Port) ->
Port ! {self(), {command, <<2:8>>}}.
+keyexists_port_command(Port, Key) ->
+ Port ! {self(), {command, <<3:8, Key/binary>>}}.
+
getvalue(Name, Key) ->
gen_server:call(Name, {getvalue, Key}, 600000).
+keyexists(Name, Key) ->
+ gen_server:call(Name, {keyexists, Key}, 600000).
+
addvalue(Name, Key, Value) ->
gen_server:call(Name, {addvalue, Key, Value}).
@@ -74,12 +80,19 @@ handle_info({Port, {data, Data}}, State) when is_port(Port) ->
addvalue ->
case Data of
<<>> ->
- util:exit_with_error(putvalue, unknown, "Error in putvalue");
+ util:exit_with_error(addvalue, unknown, "Error in addvalue");
_ ->
ok
end;
commit ->
- Data
+ Data;
+ keyexists ->
+ case Data of
+ <<0>> ->
+ false;
+ <<1>> ->
+ true
+ end
end),
{noreply, State#state{requests = Requests}};
handle_info(_Info, State) ->
@@ -115,4 +128,9 @@ handle_call({addvalue, Key, Value}, From, State) ->
handle_call({commit}, From, State) ->
lager:debug("commit ~p ~p", [State#state.name, State#state.requestcounter]),
commit_port_command(State#state.port),
- {noreply, add_request(State, From, commit)}.
+ {noreply, add_request(State, From, commit)};
+
+handle_call({keyexists, Key}, From, State) ->
+ lager:debug("keyexists ~p ~p: ~p", [State#state.name, State#state.requestcounter, Key]),
+ keyexists_port_command(State#state.port, Key),
+ {noreply, add_request(State, From, keyexists)}.