Packages

Allow erlang/BEAM applications to expose a Redis compatible protocol

Current section

Files

Jump to
edis_proto src edis_util.erl
Raw

src/edis_util.erl

%%%-------------------------------------------------------------------
%%% @author Fernando Benavides <fernando.benavides@inakanetworks.com>
%%% @author Chad DePue <chad@inakanetworks.com>
%%% @copyright (C) 2011 InakaLabs SRL
%%% @doc edis utilities
%%% @end
%%%-------------------------------------------------------------------
-module(edis_util).
-author('Fernando Benavides <fernando.benavides@inakanetworks.com>').
-author('Chad DePue <chad@inakanetworks.com>').
-export([timestamp/0, now/0, upper/1]).
-define(EPOCH, 62167219200).
%% @doc Current timestamp
-spec timestamp() -> float().
timestamp() ->
?MODULE:now() + element(3, erlang:timestamp()) / 1000000.
%% @doc UTC in *NIX seconds
-spec now() -> pos_integer().
now() ->
calendar:datetime_to_gregorian_seconds(calendar:universal_time()) - ?EPOCH.
%% @doc converts all characters in the specified binary to uppercase.
-spec upper(binary()) -> binary().
upper(Bin) ->
upper(Bin, <<>>).
%% @private
upper(<<>>, Acc) ->
Acc;
upper(<<C, Rest/binary>>, Acc) when $a =< C, C =< $z ->
upper(Rest, <<Acc/binary, (C-32)>>);
upper(<<195, C, Rest/binary>>, Acc) when 160 =< C, C =< 182 -> %% A-0 with tildes plus enye
upper(Rest, <<Acc/binary, 195, (C-32)>>);
upper(<<195, C, Rest/binary>>, Acc) when 184 =< C, C =< 190 -> %% U and Y with tilde plus greeks
upper(Rest, <<Acc/binary, 195, (C-32)>>);
upper(<<C, Rest/binary>>, Acc) ->
upper(Rest, <<Acc/binary, C>>).