Skip to content

Commit

Permalink
[RTI-13897] Use integer_to_binary/1 when possible (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
elbrujohalcon authored Feb 21, 2023
1 parent e833df8 commit 33808a9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions src/mero.erl
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ mgets(ClusterName, Keys) ->
ok | {error, Reason :: term()}.
add(ClusterName, Key, Value, ExpTime, Timeout)
when is_atom(ClusterName), is_binary(Value), is_integer(ExpTime) ->
BExpTime = list_to_binary(integer_to_list(ExpTime)),
BExpTime = integer_to_binary(ExpTime),
mero_conn:add(ClusterName, Key, Value, BExpTime, Timeout).

-spec madd(ClusterName :: atom(),
[{Key :: mero_key(), Value :: binary(), ExpTime :: integer()}],
Timeout :: integer()) ->
[ok | {error, Reason :: term()}].
madd(ClusterName, KVEs, Timeout) when is_atom(ClusterName) ->
L = [{Key, Value, list_to_binary(integer_to_list(ExpTime))}
L = [{Key, Value, integer_to_binary(ExpTime)}
|| {Key, Value, ExpTime} <- KVEs, is_binary(Key), is_binary(Value), is_integer(ExpTime)],
mero_conn:madd(ClusterName, L, Timeout).

Expand Down Expand Up @@ -191,7 +191,7 @@ mset(ClusterName, KVEs, Timeout) ->

cas(ClusterName, Key, Value, ExpTime, Timeout, CAS)
when is_atom(ClusterName), is_binary(Value), is_integer(ExpTime) ->
BExpTime = list_to_binary(integer_to_list(ExpTime)),
BExpTime = integer_to_binary(ExpTime),
%% note: if CAS is undefined, this will be an unconditional set:
mero_conn:set(ClusterName, Key, Value, BExpTime, Timeout, CAS).

Expand All @@ -203,7 +203,7 @@ cas(ClusterName, Key, Value, ExpTime, Timeout, CAS)

mcas(ClusterName, KVECs, Timeout) when is_atom(ClusterName) ->
%% note: if CAS is undefined, the corresponding set will be unconditional.
L = [{Key, Value, list_to_binary(integer_to_list(ExpTime)), CAS}
L = [{Key, Value, integer_to_binary(ExpTime), CAS}
|| {Key, Value, ExpTime, CAS} <- KVECs,
is_binary(Key),
is_binary(Value),
Expand Down Expand Up @@ -234,9 +234,9 @@ increment_counter(ClusterName, Key) when is_atom(ClusterName) ->
increment_counter(ClusterName, Key, Value, Initial, ExpTime, Retries, Timeout)
when is_integer(Value), is_integer(ExpTime), is_atom(ClusterName), Initial >= 0,
Value >= 0 ->
BValue = list_to_binary(integer_to_list(Value)),
BInitial = list_to_binary(integer_to_list(Initial)),
BExpTime = list_to_binary(integer_to_list(ExpTime)),
BValue = integer_to_binary(Value),
BInitial = integer_to_binary(Initial),
BExpTime = integer_to_binary(ExpTime),
mero_conn:increment_counter(ClusterName,
Key,
BValue,
Expand Down Expand Up @@ -265,9 +265,9 @@ mincrement_counter(ClusterName, Keys) when is_atom(ClusterName), is_list(Keys) -
mincrement_counter(ClusterName, Keys, Value, Initial, ExpTime, Timeout)
when is_list(Keys), is_integer(Value), is_integer(ExpTime), is_atom(ClusterName),
Initial >= 0, Value >= 0 ->
BValue = list_to_binary(integer_to_list(Value)),
BInitial = list_to_binary(integer_to_list(Initial)),
BExpTime = list_to_binary(integer_to_list(ExpTime)),
BValue = integer_to_binary(Value),
BInitial = integer_to_binary(Initial),
BExpTime = integer_to_binary(ExpTime),
mero_conn:mincrement_counter(ClusterName, Keys, BValue, BInitial, BExpTime, Timeout).

-spec delete(ClusterName :: atom(), Key :: mero_key(), Timeout :: integer()) ->
Expand Down
2 changes: 1 addition & 1 deletion src/mero_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ to_int(Value) when is_binary(Value) ->
to_bin(Value) when is_binary(Value) ->
Value;
to_bin(Value) when is_integer(Value) ->
to_bin(integer_to_list(Value));
integer_to_binary(Value);
to_bin(Value) when is_list(Value) ->
list_to_binary(Value).

Expand Down
6 changes: 3 additions & 3 deletions src/mero_wrk_tcp_txt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pack({?MEMCACHE_DELETE, {Key}}) when is_binary(Key) ->
pack({?MEMCACHE_DELETEQ, {Key}}) when is_binary(Key) ->
[<<"delete ">>, Key, <<" noreply ">>, <<"\r\n">>];
pack({?MEMCACHE_ADD, {Key, Initial, ExpTime}}) ->
NBytes = integer_to_list(size(Initial)),
NBytes = integer_to_binary(size(Initial)),
[<<"add ">>,
Key,
<<" ">>,
Expand All @@ -222,7 +222,7 @@ pack({?MEMCACHE_ADD, {Key, Initial, ExpTime}}) ->
Initial,
<<"\r\n">>];
pack({?MEMCACHE_SET, {Key, Initial, ExpTime, undefined}}) ->
NBytes = integer_to_list(size(Initial)),
NBytes = integer_to_binary(size(Initial)),
[<<"set ">>,
Key,
<<" ">>,
Expand All @@ -238,7 +238,7 @@ pack({?MEMCACHE_SET, {Key, Initial, ExpTime, CAS}}) when is_integer(CAS) ->
%% note: CAS should only be supplied if setting a value after looking it up. if the
%% value has changed since we looked it up, the result of a cas command will be EXISTS
%% (otherwise STORED).
NBytes = integer_to_list(size(Initial)),
NBytes = integer_to_binary(size(Initial)),
[<<"cas ">>,
Key,
<<" ">>,
Expand Down

0 comments on commit 33808a9

Please sign in to comment.