Current section

Files

Jump to
radish src radish@command@hash.erl
Raw

src/radish@command@hash.erl

-module(radish@command@hash).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function]).
-export([set/2, set_new/3, keys/1, len/1, get/2, get_all/1, mget/2, strlen/2, vals/1, del/2, exists/2, incr_by/3, incr_by_float/3, scan/3, scan_pattern/4]).
-spec set(binary(), list({binary(), binary()})) -> bitstring().
set(Key, Fields) ->
_pipe = [<<"HSET"/utf8>>, Key],
_pipe@1 = gleam@list:append(
_pipe,
gleam@list:flat_map(
Fields,
fun(Kv) -> [erlang:element(1, Kv), erlang:element(2, Kv)] end
)
),
radish@utils:prepare(_pipe@1).
-spec set_new(binary(), binary(), binary()) -> bitstring().
set_new(Key, Field, Value) ->
_pipe = [<<"HSETNX"/utf8>>, Key, Field, Value],
radish@utils:prepare(_pipe).
-spec keys(binary()) -> bitstring().
keys(Key) ->
_pipe = [<<"HKEYS"/utf8>>, Key],
radish@utils:prepare(_pipe).
-spec len(binary()) -> bitstring().
len(Key) ->
_pipe = [<<"HLEN"/utf8>>, Key],
radish@utils:prepare(_pipe).
-spec get(binary(), binary()) -> bitstring().
get(Key, Field) ->
_pipe = [<<"HGET"/utf8>>, Key, Field],
radish@utils:prepare(_pipe).
-spec get_all(binary()) -> bitstring().
get_all(Key) ->
_pipe = [<<"HGETALL"/utf8>>, Key],
radish@utils:prepare(_pipe).
-spec mget(binary(), list(binary())) -> bitstring().
mget(Key, Fields) ->
_pipe = [<<"HMGET"/utf8>>, Key],
_pipe@1 = gleam@list:append(_pipe, Fields),
radish@utils:prepare(_pipe@1).
-spec strlen(binary(), binary()) -> bitstring().
strlen(Key, Field) ->
_pipe = [<<"HSTRLEN"/utf8>>, Key, Field],
radish@utils:prepare(_pipe).
-spec vals(binary()) -> bitstring().
vals(Key) ->
_pipe = [<<"HVALS"/utf8>>, Key],
radish@utils:prepare(_pipe).
-spec del(binary(), list(binary())) -> bitstring().
del(Key, Fields) ->
_pipe = [<<"HDEL"/utf8>>, Key],
_pipe@1 = gleam@list:append(_pipe, Fields),
radish@utils:prepare(_pipe@1).
-spec exists(binary(), binary()) -> bitstring().
exists(Key, Field) ->
_pipe = [<<"HEXISTS"/utf8>>, Key, Field],
radish@utils:prepare(_pipe).
-spec incr_by(binary(), binary(), integer()) -> bitstring().
incr_by(Key, Field, Value) ->
_pipe = [<<"HINCRBY"/utf8>>, Key, Field, gleam@int:to_string(Value)],
radish@utils:prepare(_pipe).
-spec incr_by_float(binary(), binary(), float()) -> bitstring().
incr_by_float(Key, Field, Value) ->
_pipe = [<<"HINCRBYFLOAT"/utf8>>, Key, Field, gleam@float:to_string(Value)],
radish@utils:prepare(_pipe).
-spec scan(binary(), integer(), integer()) -> bitstring().
scan(Key, Cursor, Count) ->
_pipe = [<<"HSCAN"/utf8>>,
Key,
gleam@int:to_string(Cursor),
<<"COUNT"/utf8>>,
gleam@int:to_string(Count)],
radish@utils:prepare(_pipe).
-spec scan_pattern(binary(), integer(), binary(), integer()) -> bitstring().
scan_pattern(Key, Cursor, Pattern, Count) ->
_pipe = [<<"HSCAN"/utf8>>,
Key,
gleam@int:to_string(Cursor),
<<"MATCH"/utf8>>,
Pattern,
<<"COUNT"/utf8>>,
gleam@int:to_string(Count)],
radish@utils:prepare(_pipe).