Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix bug with get undefined

  • Loading branch information...
commit 7e998fe4ed6e9f85ae2677030460b5eda7c7ba51 1 parent 309b840
@0lvin authored
Showing with 19 additions and 3 deletions.
  1. +19 −3 src/merle.erl
View
22 src/merle.erl
@@ -103,12 +103,18 @@ flushall(Delay) ->
%% @doc retrieve value based off of key
getkey(Key) when is_atom(Key) ->
getkey(atom_to_list(Key));
+
getkey(Key) ->
Bin = case gen_server:call(?SERVER, {getkey,{Key}}) of
["END"] -> undefined;
[X] -> X
end,
- binary_to_term(Bin).
+ case Bin of
+ undefined ->
+ undefined;
+ _ ->
+ binary_to_term(Bin)
+ end.
%% @doc retrieve value(list only) based off of key
getkeylist(Key) when is_atom(Key) ->
@@ -118,7 +124,12 @@ getkeylist(Key) ->
["END"] -> undefined;
[X] -> X
end,
- binary_to_list(Bin).
+ case Bin of
+ undefined ->
+ undefined;
+ _ ->
+ binary_to_list(Bin)
+ end.
%% @doc retrieve value based off of key for use with cas
getskey(Key) when is_atom(Key) ->
@@ -171,6 +182,12 @@ set(Key, Value) ->
Flag = random:uniform(?RANDOM_MAX),
set(Key, integer_to_list(Flag), "0", Value).
+setlist(Key, ExpTime, Value) when is_binary(Value) ->
+ setlist(Key, ExpTime, binary_to_list(Value));
+setlist(Key, ExpTime, Value) when is_atom(Key) ->
+ setlist(atom_to_list(Key), ExpTime, Value);
+setlist(Key, ExpTime, Value) when is_integer(ExpTime) ->
+ setlist(Key, integer_to_list(ExpTime), Value);
setlist(Key, ExpTime, Value) ->
Flag = random:uniform(?RANDOM_MAX),
case gen_server:call(?SERVER, {setlist, {Key, integer_to_list(Flag), ExpTime, Value}}) of
@@ -179,7 +196,6 @@ setlist(Key, ExpTime, Value) ->
[X] -> X
end.
-
set(Key, Flag, ExpTime, Value) when is_atom(Key) ->
set(atom_to_list(Key), Flag, ExpTime, Value);
set(Key, Flag, ExpTime, Value) when is_integer(Flag) ->
Please sign in to comment.
Something went wrong with that request. Please try again.