Skip to content
Browse files

stubbed out append/prepend, increment/decrement

  • Loading branch information...
1 parent 5abea8a commit 4e588ecd2bbc7e12a0899e7dadaf053e9c044da7 zeusfaber committed Jan 18, 2009
Showing with 40 additions and 10 deletions.
  1. +40 −10 src/merle.erl
View
50 src/merle.erl
@@ -47,7 +47,7 @@
%% gen_server API
-export([
start_link/2, stats/0, stats/1, version/0, get/1, delete/2, set/4, add/4,
- replace/4, cas/5, set/2
+ replace/4, cas/5, set/2, append/2, prepend/2, increment/2, decrement/2
]).
%% gen_server callbacks
@@ -130,6 +130,22 @@ replace(Key, Flag, ExpTime, Value) ->
cas(Key, Flag, ExpTime, CasUniq, Value) ->
gen_server:call(?SERVER, {cas, {Key, Flag, ExpTime, CasUniq, Value}}).
+%% @doc Append data to already existing value.
+append(Key, Value) ->
+ gen_server:call(?SERVER, {append, {Key, Value}}).
+
+%% @doc Prepend data to already existing value.
+prepend(Key, Value) ->
+ gen_server:call(?SERVER, {prepend, {Key, Value}}).
+
+%% @doc Increment already existing value.
+increment(Key, Value) ->
+ gen_server:call(?SERVER, {increment, {Key, Value}}).
+
+%% @doc Decrement already existing value.
+decrement(Key, Value) ->
+ gen_server:call(?SERVER, {decrement, {Key, Value}}).
+
%% @private
start_link(Host, Port) ->
gen_server:start_link({local, ?SERVER}, ?MODULE, [Host, Port], []).
@@ -199,37 +215,51 @@ handle_call({replace, {Key, Flag, ExpTime, Value}}, _From, Socket) ->
),
{reply, Reply, Socket};
-handle_call({append, {Key, Value}}, _From, Socket) ->
+handle_call({cas, {Key, Flag, ExpTime, CasUniq, Value}}, _From, Socket) ->
Bin = term_to_binary(Value),
Bytes = integer_to_list(size(Bin)),
Reply = send_storage_cmd(
Socket,
- iolist_to_binary([<<"append ">>, Key, <<" 0 0 ">>, Bytes]),
+ iolist_to_binary([
+ <<"cas ">>, Key, <<" ">>, Flag, <<" ">>, ExpTime, <<" ">>, Bytes,
+ <<" ">>, CasUniq
+ ]),
Bin
),
{reply, Reply, Socket};
-handle_call({prepend, {Key, Value}}, _From, Socket) ->
+handle_call({append, {Key, Value}}, _From, Socket) ->
Bin = term_to_binary(Value),
Bytes = integer_to_list(size(Bin)),
Reply = send_storage_cmd(
Socket,
- iolist_to_binary([<<"prepend ">>, Key, <<" 0 0 ">>, Bytes]),
+ iolist_to_binary([<<"append ">>, Key, <<" 0 0 ">>, Bytes]),
Bin
),
{reply, Reply, Socket};
-handle_call({cas, {Key, Flag, ExpTime, CasUniq, Value}}, _From, Socket) ->
+handle_call({prepend, {Key, Value}}, _From, Socket) ->
Bin = term_to_binary(Value),
Bytes = integer_to_list(size(Bin)),
Reply = send_storage_cmd(
Socket,
- iolist_to_binary([
- <<"cas ">>, Key, <<" ">>, Flag, <<" ">>, ExpTime, <<" ">>, Bytes,
- <<" ">>, CasUniq
- ]),
+ iolist_to_binary([<<"prepend ">>, Key, <<" 0 0 ">>, Bytes]),
Bin
),
+ {reply, Reply, Socket};
+
+handle_call({increment, {Key, Value}}, _From, Socket) ->
+ Bin = term_to_binary(Value),
+ Reply = send_generic_cmd(
+ Socket,
+ iolist_to_binary([<<"incr ">>, Key, Bin])),
+ {reply, Reply, Socket};
+
+handle_call({decrement, {Key, Value}}, _From, Socket) ->
+ Bin = term_to_binary(Value),
+ Reply = send_generic_cmd(
+ Socket,
+ iolist_to_binary([<<"decr ">>, Key, Bin])),
{reply, Reply, Socket}.
%% @private

0 comments on commit 4e588ec

Please sign in to comment.
Something went wrong with that request. Please try again.