-module(radish@command). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]). -export([hello/1, get/1, set/3, keys/1, del/1, exists/1, incr/1, incr_by/2, incr_by_float/2, decr/1, decr_by/2]). -export_type([set_option/0]). -type set_option() :: nx | xx | get | keepttl | {ex, integer()} | {px, integer()} | {exat, integer()} | {pxat, integer()}. -spec hello(integer()) -> bitstring(). hello(Protocol) -> _pipe = [{bulk_string, <<"HELLO"/utf8>>}, {bulk_string, gleam@int:to_string(Protocol)}], _pipe@1 = {array, _pipe}, radish@encoder:encode(_pipe@1). -spec get(binary()) -> bitstring(). get(Key) -> _pipe = [{bulk_string, <<"GET"/utf8>>}, {bulk_string, Key}], _pipe@1 = {array, _pipe}, radish@encoder:encode(_pipe@1). -spec set(binary(), binary(), list(set_option())) -> bitstring(). set(Key, Value, Options) -> _pipe@4 = gleam@list:fold( Options, [{bulk_string, <<"SET"/utf8>>}, {bulk_string, Key}, {bulk_string, Value}], fun(Cmd, Option) -> case Option of nx -> gleam@list:append(Cmd, [{bulk_string, <<"NX"/utf8>>}]); xx -> gleam@list:append(Cmd, [{bulk_string, <<"XX"/utf8>>}]); get -> gleam@list:append(Cmd, [{bulk_string, <<"GET"/utf8>>}]); keepttl -> gleam@list:append(Cmd, [{bulk_string, <<"KEEPTTL"/utf8>>}]); {ex, Value@1} -> gleam@list:append( Cmd, [{bulk_string, <<"EX"/utf8>>}, {bulk_string, begin _pipe = Value@1, gleam@int:to_string(_pipe) end}] ); {px, Value@2} -> gleam@list:append( Cmd, [{bulk_string, <<"PX"/utf8>>}, {bulk_string, begin _pipe@1 = Value@2, gleam@int:to_string(_pipe@1) end}] ); {exat, Value@3} -> gleam@list:append( Cmd, [{bulk_string, <<"EXAT"/utf8>>}, {bulk_string, begin _pipe@2 = Value@3, gleam@int:to_string(_pipe@2) end}] ); {pxat, Value@4} -> gleam@list:append( Cmd, [{bulk_string, <<"PXAT"/utf8>>}, {bulk_string, begin _pipe@3 = Value@4, gleam@int:to_string(_pipe@3) end}] ) end end ), _pipe@5 = {array, _pipe@4}, radish@encoder:encode(_pipe@5). -spec keys(binary()) -> bitstring(). keys(Pattern) -> _pipe = [{bulk_string, <<"KEYS"/utf8>>}, {bulk_string, Pattern}], _pipe@1 = {array, _pipe}, radish@encoder:encode(_pipe@1). -spec del(list(binary())) -> bitstring(). del(Keys) -> _pipe = [{bulk_string, <<"DEL"/utf8>>}], _pipe@1 = gleam@list:append( _pipe, gleam@list:map(Keys, fun(Key) -> {bulk_string, Key} end) ), _pipe@2 = {array, _pipe@1}, radish@encoder:encode(_pipe@2). -spec exists(list(binary())) -> bitstring(). exists(Keys) -> _pipe = [{bulk_string, <<"EXISTS"/utf8>>}], _pipe@1 = gleam@list:append( _pipe, gleam@list:map(Keys, fun(Key) -> {bulk_string, Key} end) ), _pipe@2 = {array, _pipe@1}, radish@encoder:encode(_pipe@2). -spec incr(binary()) -> bitstring(). incr(Key) -> _pipe = [{bulk_string, <<"INCR"/utf8>>}, {bulk_string, Key}], _pipe@1 = {array, _pipe}, radish@encoder:encode(_pipe@1). -spec incr_by(binary(), integer()) -> bitstring(). incr_by(Key, Value) -> _pipe = [{bulk_string, <<"INCRBY"/utf8>>}, {bulk_string, Key}, {bulk_string, gleam@int:to_string(Value)}], _pipe@1 = {array, _pipe}, radish@encoder:encode(_pipe@1). -spec incr_by_float(binary(), float()) -> bitstring(). incr_by_float(Key, Value) -> _pipe = [{bulk_string, <<"INCRBYFLOAT"/utf8>>}, {bulk_string, Key}, {bulk_string, gleam@float:to_string(Value)}], _pipe@1 = {array, _pipe}, radish@encoder:encode(_pipe@1). -spec decr(binary()) -> bitstring(). decr(Key) -> _pipe = [{bulk_string, <<"DECR"/utf8>>}, {bulk_string, Key}], _pipe@1 = {array, _pipe}, radish@encoder:encode(_pipe@1). -spec decr_by(binary(), integer()) -> bitstring(). decr_by(Key, Value) -> _pipe = [{bulk_string, <<"DECRBY"/utf8>>}, {bulk_string, Key}, {bulk_string, gleam@int:to_string(Value)}], _pipe@1 = {array, _pipe}, radish@encoder:encode(_pipe@1).