-module(radish). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]). -export([start/3, keys/3, exists/3, get/3, mget/3, append/4, set/5, set_new/5, set_existing/5, mset/3, del/3, incr/3, incr_by/4, incr_by_float/4, decr/3, decr_by/4]). -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 = gleam@erlang@process:try_call( Client, fun(_capture) -> {command, radish@command:hello(3), _capture, Timeout} end, Timeout ), gleam@result:replace_error( _pipe, {init_failed, {abnormal, <<"Failed to say hello"/utf8>>}} ) end, fun(_) -> {ok, Client} end ) end ). -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(), gleam@option:option(integer()), integer() ) -> {ok, binary()} | {error, radish@error:error()}. set(Client, Key, Value, Ttl, Timeout) -> case Ttl of none -> radish@command:set(Key, Value, []); {some, Ttl@1} -> radish@command:set(Key, Value, [{px, Ttl@1}]) end, _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(), gleam@option:option(integer()), integer() ) -> {ok, binary()} | {error, radish@error:error()}. set_new(Client, Key, Value, Ttl, Timeout) -> case Ttl of none -> radish@command:set(Key, Value, [nx]); {some, Ttl@1} -> radish@command:set(Key, Value, [nx, {px, Ttl@1}]) end, _pipe = radish@command:set(Key, Value, [nx]), _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(), gleam@option:option(integer()), integer() ) -> {ok, binary()} | {error, radish@error:error()}. set_existing(Client, Key, Value, Ttl, Timeout) -> _pipe = case Ttl of none -> radish@command:set(Key, Value, [xx, get]); {some, Ttl@1} -> radish@command:set(Key, Value, [xx, get, {px, Ttl@1}]) end, _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: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 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: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).