Current section

Files

Jump to
radish src radish@list.erl
Raw

src/radish@list.erl

-module(radish@list).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]).
-export([lpush/4, rpush/4, lpushx/4, rpushx/4, len/3, range/5, lpop/3, blpop/3, rpop/3, brpop/3, lpop_multiple/4, rpop_multiple/4, index/4, 'rem'/5, set/5, insert_after/5, insert_before/5]).
-spec lpush(
gleam@erlang@process:subject(radish@client:message()),
binary(),
list(binary()),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
lpush(Client, Key, Values, Timeout) ->
_pipe = radish@command@list:lpush(Key, Values),
_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 rpush(
gleam@erlang@process:subject(radish@client:message()),
binary(),
list(binary()),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
rpush(Client, Key, Values, Timeout) ->
_pipe = radish@command@list:rpush(Key, Values),
_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 lpushx(
gleam@erlang@process:subject(radish@client:message()),
binary(),
list(binary()),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
lpushx(Client, Key, Values, Timeout) ->
_pipe = radish@command@list:lpushx(Key, Values),
_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 rpushx(
gleam@erlang@process:subject(radish@client:message()),
binary(),
list(binary()),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
rpushx(Client, Key, Values, Timeout) ->
_pipe = radish@command@list:rpushx(Key, Values),
_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 len(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
len(Client, Key, Timeout) ->
_pipe = radish@command@list:len(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 range(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer(),
integer(),
integer()
) -> {ok, list(binary())} | {error, radish@error:error()}.
range(Client, Key, Start, End, Timeout) ->
_pipe = radish@command@list:range(Key, Start, End),
_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 lpop(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer()
) -> {ok, binary()} | {error, radish@error:error()}.
lpop(Client, Key, Timeout) ->
_pipe = radish@command@list:lpop(Key, none),
_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};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec blpop(
gleam@erlang@process:subject(radish@client:message()),
list(binary()),
integer()
) -> {ok, list({binary(), binary()})} | {error, radish@error:error()}.
blpop(Client, Keys, Timeout) ->
_pipe = radish@command@list:blpop(Keys, Timeout),
_pipe@1 = radish@utils:execute_blocking(Client, _pipe, Timeout),
_pipe@3 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
[{array, Array}] ->
_pipe@2 = gleam@list:sized_chunk(Array, 2),
gleam@list:try_map(_pipe@2, fun(Kv) -> case Kv of
[{bulk_string, Key}, {bulk_string, Value@1}] ->
{ok, {Key, Value@1}};
_ ->
{error, resp_error}
end end);
[null] ->
{error, not_found};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@3).
-spec rpop(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer()
) -> {ok, binary()} | {error, radish@error:error()}.
rpop(Client, Key, Timeout) ->
_pipe = radish@command@list:rpop(Key, none),
_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};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec brpop(
gleam@erlang@process:subject(radish@client:message()),
list(binary()),
integer()
) -> {ok, list({binary(), binary()})} | {error, radish@error:error()}.
brpop(Client, Keys, Timeout) ->
_pipe = radish@command@list:brpop(Keys, Timeout),
_pipe@1 = radish@utils:execute_blocking(Client, _pipe, Timeout),
_pipe@3 = gleam@result:map(_pipe@1, fun(Value) -> case Value of
[{array, Array}] ->
_pipe@2 = gleam@list:sized_chunk(Array, 2),
gleam@list:try_map(_pipe@2, fun(Kv) -> case Kv of
[{bulk_string, Key}, {bulk_string, Value@1}] ->
{ok, {Key, Value@1}};
_ ->
{error, resp_error}
end end);
[null] ->
{error, not_found};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@3).
-spec lpop_multiple(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer(),
integer()
) -> {ok, list(binary())} | {error, radish@error:error()}.
lpop_multiple(Client, Key, Count, Timeout) ->
_pipe = radish@command@list:lpop(Key, {some, Count}),
_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 rpop_multiple(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer(),
integer()
) -> {ok, list(binary())} | {error, radish@error:error()}.
rpop_multiple(Client, Key, Count, Timeout) ->
_pipe = radish@command@list:rpop(Key, {some, Count}),
_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 index(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer(),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
index(Client, Key, Index, Timeout) ->
_pipe = radish@command@list:index(Key, Index),
_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 'rem'(
gleam@erlang@process:subject(radish@client:message()),
binary(),
integer(),
binary(),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
'rem'(Client, Key, Count, Value, Timeout) ->
_pipe = radish@command@list:'rem'(Key, Count, 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(),
integer(),
binary(),
integer()
) -> {ok, binary()} | {error, radish@error:error()}.
set(Client, Key, Index, Value, Timeout) ->
_pipe = radish@command@list:set(Key, Index, 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};
_ ->
{error, resp_error}
end end),
gleam@result:flatten(_pipe@2).
-spec insert_after(
gleam@erlang@process:subject(radish@client:message()),
binary(),
binary(),
binary(),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
insert_after(Client, Key, Pivot, Value, Timeout) ->
_pipe = radish@command@list:insert_after(Key, Pivot, 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 insert_before(
gleam@erlang@process:subject(radish@client:message()),
binary(),
binary(),
binary(),
integer()
) -> {ok, integer()} | {error, radish@error:error()}.
insert_before(Client, Key, Pivot, Value, Timeout) ->
_pipe = radish@command@list:insert_before(Key, Pivot, 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).