Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed that horrible base64 encoding.

My bench went down from 25 sec to 15 sec.
  • Loading branch information...
commit 91b1bc490302367229506281c98dadc2204a311e 1 parent 23dd6d9
@cstar cstar authored
Showing with 17 additions and 11 deletions.
  1. +17 −11 riak_redis_backend.erl
View
28 riak_redis_backend.erl
@@ -4,6 +4,9 @@
%% a copy of the License at
%% http://www.apache.org/licenses/LICENSE-2.0
+%%[{ totals, 4239, 44.484, 22.362}].
+%%[{ totals, 4951, 36.381, 26.965}].
+
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
@@ -38,7 +41,7 @@ stop(_State)->
% get(state(), Key :: binary()) ->
% {ok, Val :: binary()} | {error, Reason :: term()}
get(#state{pid=Pid}, BK)->
- case erldis:get(Pid, t2l(BK)) of
+ case erldis:get(Pid, k2l(BK)) of
nil -> {error, notfound};
Val -> {ok, l2t(Val)}
end.
@@ -48,12 +51,12 @@ get(#state{pid=Pid}, BK)->
put(#state{pid=Pid}, {Bucket, Key}=BK, Value)->
%riak_eventer:notify(riak_redis_backend, put, {{Bucket, Key}, Value}),
check_bucket(Pid, Bucket),
- case erldis:set(Pid, t2l(BK), t2l(Value)) of
+ case erldis:set(Pid, k2l(BK), t2l(Value)) of
ok ->
- case {erldis:sismember(Pid, t2l(Bucket), t2l(Key)),
+ case {erldis:sismember(Pid, binary_to_list(Bucket), t2l(Key)),
erldis:sismember(Pid, "world", t2l(BK))} of
{false, false} ->
- erldis:sadd(Pid, t2l(Bucket), t2l(Key)),
+ erldis:sadd(Pid, binary_to_list(Bucket), t2l(Key)),
erldis:sadd(Pid, "world", t2l(BK)),
ok;
_ ->
@@ -65,12 +68,12 @@ put(#state{pid=Pid}, {Bucket, Key}=BK, Value)->
% delete(state(), Key :: binary()) ->
% ok | {error, Reason :: term()}
delete(#state { pid=Pid }, {Bucket, Key}=BK) ->
- case erldis:del(Pid, t2l(BK)) of
+ case erldis:del(Pid, k2l(BK)) of
true ->
- case {erldis:sismember(Pid, t2l(Bucket), t2l(Key)),
+ case {erldis:sismember(Pid, binary_to_list(Bucket), t2l(Key)),
erldis:sismember(Pid, "world", t2l(BK))} of
{true, true} ->
- erldis:srem(Pid, t2l(Bucket), t2l(Key)),
+ erldis:srem(Pid, binary_to_list(Bucket), t2l(Key)),
erldis:srem(Pid, "world", t2l(BK)),
ok;
_ ->
@@ -93,7 +96,7 @@ list_bucket(#state { pid=Pid }, '_')->
erldis:smembers(Pid, "buckets"));
list_bucket(#state { pid=Pid }, {filter, Bucket, Fun})->
- KL = lists:filter(Fun, erldis:smembers(Pid, t2l(Bucket))),
+ KL = lists:filter(Fun, erldis:smembers(Pid, binary_to_list(Bucket))),
lists:map(fun(Key)->
l2t(Key)
end, KL);
@@ -101,7 +104,7 @@ list_bucket(#state { pid=Pid }, Bucket) ->
lists:map(fun(Key)->
l2t(Key)
end,
- erldis:smembers(Pid, t2l(Bucket))).
+ erldis:smembers(Pid, binary_to_list(Bucket))).
check_bucket(Pid,Bucket)->
B = t2l(Bucket),
@@ -112,8 +115,11 @@ check_bucket(Pid,Bucket)->
erldis:sadd(Pid, "buckets",B)
end.
+
+k2l({B, V})->
+ binary_to_list(list_to_binary([B, V])).
t2l(V)->
- binary_to_list(base64:encode(term_to_binary(V))).
+ binary_to_list(term_to_binary(V)).
l2t(V)->
- binary_to_term(base64:decode(list_to_binary(V))).
+ binary_to_term(list_to_binary(V)).
Please sign in to comment.
Something went wrong with that request. Please try again.