Current section
Files
Jump to
Current section
Files
src/radish.erl
-module(radish).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]).
-export([start/3, shutdown/1, keys/3, exists/3, get/3, mget/3, append/4, set/4, set_new/4, set_existing/4, mset/3, del/3, incr/3, incr_by/4, incr_by_float/4, decr/3, decr_by/4, random_key/2, key_type/3, rename/4, renamenx/4, persist/3, expire/4, expire_if/5]).
-spec start(binary(), integer(), integer()) -> {ok,
gleam@erlang@process:subject(radish@client:message())} |
{error, gleam@otp@actor:start_error()}.
start(Host, Port, Timeout) ->
gleam@result:then(
radish@client:start(Host, Port, Timeout),
fun(Client) ->
gleam@result:then(
begin
_pipe = radish@utils:execute(
Client,
radish@command:hello(3),
Timeout
),
gleam@result:replace_error(
_pipe,
{init_failed,
{abnormal, <<"Failed to say hello"/utf8>>}}
)
end,
fun(_) -> {ok, Client} end
)
end
).
-spec shutdown(gleam@erlang@process:subject(radish@client:message())) -> nil.
shutdown(Client) ->
gleam@erlang@process:send(Client, shutdown).
-spec keys(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer()
) -> {ok, list(binary())} | {error, radish@error:error()}.
keys(Client, Pattern, Timeout) ->
_pipe = radish@command:keys(Pattern),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{array, Array} ->
gleam@list:try_map(Array, fun(Item) -> case Item of
{bulk_string, Value@1} ->
{ok, Value@1};
_ ->
{error, resp_error}
end end);
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec exists(
gleam@erlang@process:subject(radish@client:message()),
list(binary()),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
exists(Client, Keys, Timeout) ->
_pipe = radish@command:exists(Keys),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{integer, N} ->
{ok, N};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec get(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer()
) -> {ok, binary()} | {error, radish@error:error()}.
get(Client, Key, Timeout) ->
_pipe = radish@command:get(Key),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{simple_string, Str} ->
{ok, Str};
{bulk_string, Str} ->
{ok, Str};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec mget(
gleam@erlang@process:subject(radish@client:message()),
list(binary()),
integer()
) -> {ok, list(binary())} | {error, radish@error:error()}.
mget(Client, Keys, Timeout) ->
_pipe = radish@command:mget(Keys),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{array, Array} ->
gleam@list:try_map(Array, fun(Item) -> case Item of
{bulk_string, Str} ->
{ok, Str};
_ ->
{error, resp_error}
end end);
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec append(
gleam@erlang@process:subject(radish@client:message()),
binary(),
binary(),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
append(Client, Key, Value, Timeout) ->
_pipe = radish@command:append(Key, Value),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value@1) -> case Value@1 of
{integer, N} ->
{ok, N};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec set(
gleam@erlang@process:subject(radish@client:message()),
binary(),
binary(),
integer()
) -> {ok, binary()} | {error, radish@error:error()}.
set(Client, Key, Value, Timeout) ->
_pipe = radish@command:set(Key, Value, []),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value@1) -> case Value@1 of
{simple_string, Str} ->
{ok, Str};
{bulk_string, Str} ->
{ok, Str};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec set_new(
gleam@erlang@process:subject(radish@client:message()),
binary(),
binary(),
integer()
) -> {ok, binary()} | {error, radish@error:error()}.
set_new(Client, Key, Value, Timeout) ->
_pipe = radish@command:set(Key, Value, [snx]),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value@1) -> case Value@1 of
{simple_string, Str} ->
{ok, Str};
{bulk_string, Str} ->
{ok, Str};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec set_existing(
gleam@erlang@process:subject(radish@client:message()),
binary(),
binary(),
integer()
) -> {ok, binary()} | {error, radish@error:error()}.
set_existing(Client, Key, Value, Timeout) ->
_pipe = radish@command:set(Key, Value, [sxx, get]),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value@1) -> case Value@1 of
{simple_string, Str} ->
{ok, Str};
{bulk_string, Str} ->
{ok, Str};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec mset(
gleam@erlang@process:subject(radish@client:message()),
list({binary(), binary()}),
integer()
) -> {ok, binary()} | {error, radish@error:error()}.
mset(Client, Kv_list, Timeout) ->
_pipe = radish@command:mset(Kv_list),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{simple_string, Str} ->
{ok, Str};
{bulk_string, Str} ->
{ok, Str};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec del(
gleam@erlang@process:subject(radish@client:message()),
list(binary()),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
del(Client, Keys, Timeout) ->
_pipe = radish@command:del(Keys),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{integer, N} ->
{ok, N};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec incr(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
incr(Client, Key, Timeout) ->
_pipe = radish@command:incr(Key),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{integer, New} ->
{ok, New};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec incr_by(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer(),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
incr_by(Client, Key, Value, Timeout) ->
_pipe = radish@command:incr_by(Key, Value),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value@1) -> case Value@1 of
{integer, New} ->
{ok, New};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec incr_by_float(
gleam@erlang@process:subject(radish@client:message()),
binary(),
float(),
integer()
) -> {ok, float()} | {error, radish@error:error()}.
incr_by_float(Client, Key, Value, Timeout) ->
_pipe = radish@command:incr_by_float(Key, Value),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@3 = gleam@result:map(_pipe@1, fun(Value@1) -> case Value@1 of
{bulk_string, New} ->
_pipe@2 = gleam@float:parse(New),
gleam@result:replace_error(_pipe@2, resp_error);
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@3).
-spec decr(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
decr(Client, Key, Timeout) ->
_pipe = radish@command:decr(Key),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{integer, New} ->
{ok, New};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec decr_by(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer(),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
decr_by(Client, Key, Value, Timeout) ->
_pipe = radish@command:decr_by(Key, Value),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value@1) -> case Value@1 of
{integer, New} ->
{ok, New};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec random_key(
gleam@erlang@process:subject(radish@client:message()),
integer()
) -> {ok, binary()} | {error, radish@error:error()}.
random_key(Client, Timeout) ->
_pipe = radish@command:random_key(),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{bulk_string, Str} ->
{ok, Str};
null ->
{error, empty_db_error};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec key_type(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer()
) -> {ok, binary()} | {error, radish@error:error()}.
key_type(Client, Key, Timeout) ->
_pipe = radish@command:key_type(Key),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{simple_string, Str} ->
{ok, Str};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec rename(
gleam@erlang@process:subject(radish@client:message()),
binary(),
binary(),
integer()
) -> {ok, binary()} | {error, radish@error:error()}.
rename(Client, Key, New_key, Timeout) ->
_pipe = radish@command:rename(Key, New_key),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{simple_string, Str} ->
{ok, Str};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec renamenx(
gleam@erlang@process:subject(radish@client:message()),
binary(),
binary(),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
renamenx(Client, Key, New_key, Timeout) ->
_pipe = radish@command:renamenx(Key, New_key),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{integer, N} ->
{ok, N};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec persist(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
persist(Client, Key, Timeout) ->
_pipe = radish@command:persist(Key),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{integer, N} ->
{ok, N};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec expire(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer(),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
expire(Client, Key, Ttl, Timeout) ->
_pipe = radish@command:expire(Key, Ttl, none),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{integer, N} ->
{ok, N};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec expire_if(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer(),
radish@command:expire_condition(),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
expire_if(Client, Key, Ttl, Condition, Timeout) ->
_pipe = radish@command:expire(Key, Ttl, {some, Condition}),
_pipe@1 = radish@utils:execute(Client, _pipe, Timeout),
_pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
{integer, N} ->
{ok, N};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).