-module(radish@sorted_set). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]). -export([card/3, score/4, 'rem'/4, count/5, add_new/4, upsert/4, upsert_only_lower_scores/4, upsert_only_higher_scores/4, update/4, update_only_lower_scores/4, update_only_higher_scores/4, incr_by/5, random_members/4, rank/4, reverse_rank/4, pop_min/4, pop_max/4, scan/5, scan_pattern/6]). -export_type([score/0]). -type score() :: infinity | {double, float()} | negative_infinity. -spec card( gleam@erlang@process:subject(radish@client:message()), binary(), integer() ) -> {ok, integer()} | {error, radish@error:error()}. card(Client, Key, Timeout) -> _pipe = radish@command@sorted_set:card(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 score( gleam@erlang@process:subject(radish@client:message()), binary(), binary(), integer() ) -> {ok, score()} | {error, radish@error:error()}. score(Client, Key, Member, Timeout) -> _pipe = radish@command@sorted_set:score(Key, Member), _pipe@1 = radish@utils:execute(Client, _pipe, Timeout), _pipe@2 = gleam@result:map(_pipe@1, fun(Value) -> case Value of infinity -> {ok, infinity}; {double, Score} -> {ok, {double, Score}}; negative_infinity -> {ok, negative_infinity}; null -> {error, not_found}; _ -> {error, resp_error} end end), gleam@result:flatten(_pipe@2). -spec 'rem'( gleam@erlang@process:subject(radish@client:message()), binary(), list(binary()), integer() ) -> {ok, integer()} | {error, radish@error:error()}. 'rem'(Client, Key, Members, Timeout) -> _pipe = radish@command@sorted_set:'rem'(Key, Members), _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 encode_score(score()) -> binary(). encode_score(Score) -> case Score of infinity -> <<"+inf"/utf8>>; negative_infinity -> <<"-inf"/utf8>>; {double, Score@1} -> gleam@float:to_string(Score@1) end. -spec count( gleam@erlang@process:subject(radish@client:message()), binary(), score(), score(), integer() ) -> {ok, integer()} | {error, radish@error:error()}. count(Client, Key, Min, Max, Timeout) -> _pipe = radish@command@sorted_set:count( Key, encode_score(Min), encode_score(Max) ), _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 encode_member({binary(), score()}) -> {binary(), binary()}. encode_member(Member) -> {erlang:element(1, Member), encode_score(erlang:element(2, Member))}. -spec add_new( gleam@erlang@process:subject(radish@client:message()), binary(), list({binary(), score()}), integer() ) -> {ok, integer()} | {error, radish@error:error()}. add_new(Client, Key, Members, Timeout) -> _pipe = radish@command@sorted_set:add_new( Key, gleam@list:map(Members, fun encode_member/1) ), _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 upsert( gleam@erlang@process:subject(radish@client:message()), binary(), list({binary(), score()}), integer() ) -> {ok, integer()} | {error, radish@error:error()}. upsert(Client, Key, Members, Timeout) -> _pipe = radish@command@sorted_set:upsert( Key, gleam@list:map(Members, fun encode_member/1) ), _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 upsert_only_lower_scores( gleam@erlang@process:subject(radish@client:message()), binary(), list({binary(), score()}), integer() ) -> {ok, integer()} | {error, radish@error:error()}. upsert_only_lower_scores(Client, Key, Members, Timeout) -> _pipe = radish@command@sorted_set:upsert_only_lower_scores( Key, gleam@list:map(Members, fun encode_member/1) ), _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 upsert_only_higher_scores( gleam@erlang@process:subject(radish@client:message()), binary(), list({binary(), score()}), integer() ) -> {ok, integer()} | {error, radish@error:error()}. upsert_only_higher_scores(Client, Key, Members, Timeout) -> _pipe = radish@command@sorted_set:upsert_only_higher_scores( Key, gleam@list:map(Members, fun encode_member/1) ), _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 update( gleam@erlang@process:subject(radish@client:message()), binary(), list({binary(), score()}), integer() ) -> {ok, integer()} | {error, radish@error:error()}. update(Client, Key, Members, Timeout) -> _pipe = radish@command@sorted_set:update( Key, gleam@list:map(Members, fun encode_member/1) ), _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 update_only_lower_scores( gleam@erlang@process:subject(radish@client:message()), binary(), list({binary(), score()}), integer() ) -> {ok, integer()} | {error, radish@error:error()}. update_only_lower_scores(Client, Key, Members, Timeout) -> _pipe = radish@command@sorted_set:update_only_lower_scores( Key, gleam@list:map(Members, fun encode_member/1) ), _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 update_only_higher_scores( gleam@erlang@process:subject(radish@client:message()), binary(), list({binary(), score()}), integer() ) -> {ok, integer()} | {error, radish@error:error()}. update_only_higher_scores(Client, Key, Members, Timeout) -> _pipe = radish@command@sorted_set:update_only_higher_scores( Key, gleam@list:map(Members, fun encode_member/1) ), _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 map_score(radish@resp:value()) -> {ok, score()} | {error, radish@error:error()}. map_score(Score) -> case Score of infinity -> {ok, infinity}; {double, Score@1} -> {ok, {double, Score@1}}; negative_infinity -> {ok, negative_infinity}; _ -> {error, resp_error} end. -spec incr_by( gleam@erlang@process:subject(radish@client:message()), binary(), binary(), score(), integer() ) -> {ok, score()} | {error, radish@error:error()}. incr_by(Client, Key, Member, Change_in_score, Timeout) -> _pipe = radish@command@sorted_set:incr_by( Key, Member, encode_score(Change_in_score) ), _pipe@1 = radish@utils:execute(Client, _pipe, Timeout), _pipe@2 = gleam@result:map(_pipe@1, fun map_score/1), gleam@result:flatten(_pipe@2). -spec random_members( gleam@erlang@process:subject(radish@client:message()), binary(), integer(), integer() ) -> {ok, list({binary(), score()})} | {error, radish@error:error()}. random_members(Client, Key, Count, Timeout) -> _pipe = radish@command@sorted_set:random_members(Key, Count), _pipe@1 = radish@utils:execute(Client, _pipe, Timeout), _pipe@3 = gleam@result:map(_pipe@1, fun(Value) -> case Value of {array, Members} -> gleam@result:then( begin _pipe@2 = Members, gleam@list:try_map( _pipe@2, fun(Item) -> case Item of {array, [{bulk_string, Member}, Score]} -> case map_score(Score) of {ok, Score@1} -> {ok, {Member, Score@1}}; _ -> {error, resp_error} end; _ -> {error, resp_error} end end ) end, fun(Array) -> {ok, Array} end ); _ -> {error, resp_error} end end), gleam@result:flatten(_pipe@3). -spec rank( gleam@erlang@process:subject(radish@client:message()), binary(), binary(), integer() ) -> {ok, {integer(), score()}} | {error, radish@error:error()}. rank(Client, Key, Member, Timeout) -> _pipe = radish@command@sorted_set:rank(Key, Member), _pipe@1 = radish@utils:execute(Client, _pipe, Timeout), _pipe@4 = gleam@result:map(_pipe@1, fun(Value) -> case Value of {array, [{integer, Rank}, Score]} -> _pipe@2 = Score, _pipe@3 = map_score(_pipe@2), gleam@result:map( _pipe@3, fun(Score@1) -> {Rank, Score@1} end ); null -> {error, not_found}; _ -> {error, resp_error} end end), gleam@result:flatten(_pipe@4). -spec reverse_rank( gleam@erlang@process:subject(radish@client:message()), binary(), binary(), integer() ) -> {ok, {integer(), score()}} | {error, radish@error:error()}. reverse_rank(Client, Key, Member, Timeout) -> _pipe = radish@command@sorted_set:reverse_rank(Key, Member), _pipe@1 = radish@utils:execute(Client, _pipe, Timeout), _pipe@4 = gleam@result:map(_pipe@1, fun(Value) -> case Value of {array, [{integer, Rank}, Score]} -> _pipe@2 = Score, _pipe@3 = map_score(_pipe@2), gleam@result:map( _pipe@3, fun(Score@1) -> {Rank, Score@1} end ); null -> {error, not_found}; _ -> {error, resp_error} end end), gleam@result:flatten(_pipe@4). -spec pop_min( gleam@erlang@process:subject(radish@client:message()), binary(), integer(), integer() ) -> {ok, list({binary(), score()})} | {error, radish@error:error()}. pop_min(Client, Key, Count, Timeout) -> _pipe = radish@command@sorted_set:pop_min(Key, Count), _pipe@1 = radish@utils:execute(Client, _pipe, Timeout), _pipe@3 = gleam@result:map(_pipe@1, fun(Value) -> case Value of {array, Members} -> gleam@result:then( begin _pipe@2 = Members, gleam@list:try_map( _pipe@2, fun(Item) -> case Item of {array, [{bulk_string, Member}, Score]} -> case map_score(Score) of {ok, Score@1} -> {ok, {Member, Score@1}}; _ -> {error, resp_error} end; _ -> {error, resp_error} end end ) end, fun(Array) -> {ok, Array} end ); _ -> {error, resp_error} end end), gleam@result:flatten(_pipe@3). -spec pop_max( gleam@erlang@process:subject(radish@client:message()), binary(), integer(), integer() ) -> {ok, list({binary(), score()})} | {error, radish@error:error()}. pop_max(Client, Key, Count, Timeout) -> _pipe = radish@command@sorted_set:pop_max(Key, Count), _pipe@1 = radish@utils:execute(Client, _pipe, Timeout), _pipe@3 = gleam@result:map(_pipe@1, fun(Value) -> case Value of {array, Members} -> gleam@result:then( begin _pipe@2 = Members, gleam@list:try_map( _pipe@2, fun(Item) -> case Item of {array, [{bulk_string, Member}, Score]} -> case map_score(Score) of {ok, Score@1} -> {ok, {Member, Score@1}}; _ -> {error, resp_error} end; _ -> {error, resp_error} end end ) end, fun(Array) -> {ok, Array} end ); _ -> {error, resp_error} end end), gleam@result:flatten(_pipe@3). -spec decode_score(binary()) -> {ok, score()} | {error, nil}. decode_score(Score) -> case Score of <<"+inf"/utf8>> -> {ok, infinity}; <<"inf"/utf8>> -> {ok, infinity}; <<"-inf"/utf8>> -> {ok, negative_infinity}; _ -> case gleam@int:parse(Score) of {ok, Score@1} -> _pipe = Score@1, _pipe@1 = gleam@int:to_float(_pipe), _pipe@2 = {double, _pipe@1}, {ok, _pipe@2}; {error, nil} -> _pipe@3 = Score, _pipe@4 = gleam@float:parse(_pipe@3), gleam@result:map( _pipe@4, fun(Field@0) -> {double, Field@0} end ) end end. -spec scan( gleam@erlang@process:subject(radish@client:message()), binary(), integer(), integer(), integer() ) -> {ok, {list({binary(), score()}), integer()}} | {error, radish@error:error()}. scan(Client, Key, Cursor, Count, Timeout) -> _pipe = radish@command@sorted_set:scan(Key, Cursor, Count), _pipe@1 = radish@utils:execute(Client, _pipe, Timeout), _pipe@4 = gleam@result:map(_pipe@1, fun(Value) -> case Value of {array, [{bulk_string, New_cursor_str}, {array, Members}]} -> case gleam@int:parse(New_cursor_str) of {ok, New_cursor} -> gleam@result:then( begin _pipe@2 = Members, _pipe@3 = gleam@list:sized_chunk(_pipe@2, 2), gleam@list:try_map( _pipe@3, fun(Item) -> case Item of [{bulk_string, Member}, {bulk_string, Score}] -> case decode_score(Score) of {ok, Score@1} -> {ok, {Member, Score@1}}; _ -> {error, resp_error} end; _ -> {error, resp_error} end end ) end, fun(Array) -> {ok, {Array, New_cursor}} end ); {error, nil} -> {error, resp_error} end; _ -> {error, resp_error} end end), gleam@result:flatten(_pipe@4). -spec scan_pattern( gleam@erlang@process:subject(radish@client:message()), binary(), integer(), binary(), integer(), integer() ) -> {ok, {list({binary(), score()}), integer()}} | {error, radish@error:error()}. scan_pattern(Client, Key, Cursor, Pattern, Count, Timeout) -> _pipe = radish@command@sorted_set:scan_pattern(Key, Cursor, Pattern, Count), _pipe@1 = radish@utils:execute(Client, _pipe, Timeout), _pipe@4 = gleam@result:map(_pipe@1, fun(Value) -> case Value of {array, [{bulk_string, New_cursor_str}, {array, Members}]} -> case gleam@int:parse(New_cursor_str) of {ok, New_cursor} -> gleam@result:then( begin _pipe@2 = Members, _pipe@3 = gleam@list:sized_chunk(_pipe@2, 2), gleam@list:try_map( _pipe@3, fun(Item) -> case Item of [{bulk_string, Member}, {bulk_string, Score}] -> case decode_score(Score) of {ok, Score@1} -> {ok, {Member, Score@1}}; _ -> {error, resp_error} end; _ -> {error, resp_error} end end ) end, fun(Array) -> {ok, {Array, New_cursor}} end ); {error, nil} -> {error, resp_error} end; _ -> {error, resp_error} end end), gleam@result:flatten(_pipe@4).