Flux Redis v0.0.2 FluxRedis.HashManager View Source
Manage Redis Hash data as a JSON storage.
After defining hash_storages on your FluxRedis application configuration,
you can use the functions of this module to manage hashes and hash fields as
JSON storage.
A Redis hash maintain a JSON data in each field. Each hash field name is
defined according to the keys defined by a hash in hash_storages.
For more information about application configuration, check FluxRedis main
module and homepage.
Command Options
:no_reply?- Iftrue, the function returns:okafter successfully send the request to Redis. Disabled (false) in get-type functions and defaults totruein set-type functions. Acceptsboolean/0.:timeout- Milliseconds to wait for a request sending. Defaults to5_000. Acceptsinteger/0or:infinity.
Link to this section Summary
Functions
Count the number of fields in a hash.
Count the number of fields in a hash.
Removes a field from a hash.
Removes a field from a hash.
Removes one or more fields from a hash.
Removes one or more fields from a hash.
Retrieves a field from a hash.
Retrieves a field from a hash.
Retrieves all fields in a hash.
Retrieves all fields in a hash.
Retrieves one or more fields in a hash.
Retrieves one or more fields in a hash.
Retrieves one or more fields that match key values pattern in a hash.
Retrieves one or more fields that match key values pattern in a hash.
Check if field exists in a hash.
Check if field exists in a hash.
Add or update a field in a hash.
Add or update a field in a hash.
Add or update one or more fields in a hash.
Add or update one or more fields in a hash.
Add a field in a hash.
Add a field in a hash.
Link to this section Types
Link to this section Functions
count(hash, opts \\ [])
View Source (since 0.0.2)count(atom(), keyword()) :: {:ok, integer()} | {:error, FluxRedis.Error.t()}
Count the number of fields in a hash.
Returns {:ok, integer} in case of success or {:error, %FluxRedis.Error{}}
otherwise.
This function always sets :no_reply? option to false.
Parameters
hash- Theatom/0defined inFluxRedishash_storagesapplication configuration.opts-keyword/0of options. CheckFluxRedis.HashManagerfor more information.
Examples
iex> hash_storages = [users: :id]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> users = [%{id: 1, name: "John"}, %{id: 2, name: "Doe"}]
...> FluxRedis.HashManager.set_many(:users, users)
...> FluxRedis.HashManager.count(:users)
{:ok, 2}
Count the number of fields in a hash.
Similar to count/2, but raises FluxRedis.Error.t/0 on failure.
Examples
iex> hash_storages = [users: :id]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> users = [%{id: 1, name: "John"}, %{id: 2, name: "Doe"}]
...> FluxRedis.HashManager.set_many(:users, users)
...> FluxRedis.HashManager.count!(:users)
2
delete(hash, key_data, opts \\ [no_reply?: true])
View Source (since 0.0.2)delete(atom(), [key_data()] | key_data(), keyword()) :: :ok | {:error, FluxRedis.Error.t()}
Removes a field from a hash.
Returns :ok in case of success or {:error, %FluxRedis.Error{}} otherwise.
By default, the option no_reply? is set to true.
Parameters
hash- Theatom/0defined inFluxRedishash_storagesapplication configuration.key_data- Thekey_data/0with the values of each key defined inFluxRedishash_storagesapplication configuration.opts-keyword/0with command options. CheckFluxRedis.HashManagerfor more information.
Examples
iex> hash_storages = [cars: [:brand, :model]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> car = %{brand: "Honda", model: "Civic", year: 2019}
...> FluxRedis.HashManager.set(:cars, car)
...> FluxRedis.HashManager.delete(:cars, ["Honda", "Civic"])
:ok
Removes a field from a hash.
Similar to delete/3, but raises FluxRedis.Error.t/0 on failure.
Examples
iex> hash_storages = [cars: [:brand, :model]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> car = %{brand: "Honda", model: "Civic", year: 2019}
...> FluxRedis.HashManager.set(:cars, car)
...> FluxRedis.HashManager.delete(:cars, ["Honda", "Civic"])
:ok
delete_many(hash, key_data_list, opts \\ [no_reply?: true])
View Source (since 0.0.2)delete_many(atom(), key_data_list(), keyword()) :: :ok | {:ok, integer()} | {:error, FluxRedis.Error.t()}
Removes one or more fields from a hash.
Returns :ok in case of successful request and no_reply? is set to true.
Returns {:ok, amount_removed} in case of success and no_reply? is set to
false.
Returns {:error, %FluxRedis.Error{}} on failure.
By default, the option no_reply? is set to true.
Parameters
hash- Theatom/0defined inFluxRedishash_storagesapplication configuration.key_data_list- Thekey_data_list/0with the values of each key defined inFluxRedishash_storagesapplication configuration.opts-keyword/0with command options. CheckFluxRedis.HashManagerfor more information.
Examples
iex> hash_storages = [animals: [:phylum, :family]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> animals = [
...> %{family: "Canidae", phylum: "Chordata"},
...> %{family: "Felidae", phylum: "Chordata"}
...> ]
...> FluxRedis.HashManager.set_many(:animals, animals)
...> animals_keys = [["Chordata", "Canidae"], ["Chordata", "Felidae"]]
...> alias FluxRedis.HashManager
...> HashManager.delete_many(:animals, animals_keys, no_reply?: false)
{:ok, 2}
delete_many!(hash, key_data_list, opts \\ [no_reply?: true])
View Source (since 0.0.2)delete_many!(atom(), key_data_list(), keyword()) :: :ok | integer()
Removes one or more fields from a hash.
Similar to delete_many/3, but raises FluxRedis.Error.t/0 on failure.
Examples
iex> hash_storages = [animals: [:phylum, :family]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> animals = [
...> %{family: "Canidae", phylum: "Chordata"},
...> %{family: "Felidae", phylum: "Chordata"}
...> ]
...> FluxRedis.HashManager.set_many(:animals, animals)
...> animals_keys = [["Chordata", "Canidae"], ["Chordata", "Felidae"]]
...> alias FluxRedis.HashManager
...> HashManager.delete_many!(:animals, animals_keys, no_reply?: false)
2
Retrieves a field from a hash.
Returns {:ok, field} in case of success or {:error, %FluxRedis.Error{}}
otherwise.
This function always sets :no_reply? option to false.
Parameters
hash- Theatom/0defined inFluxRedishash_storagesapplication configuration.key_data- Thekey_data/0with the values of each key defined inFluxRedishash_storagesapplication configuration.opts-keyword/0with command options. CheckFluxRedis.HashManagerfor more information.
Examples
iex> hash_storages = [cars: [:brand, :model]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> car = %{brand: "Honda", model: "Civic", year: 2019}
...> FluxRedis.HashManager.set(:cars, car)
...> FluxRedis.HashManager.get(:cars, ["Honda", "Civic"])
{:ok, %{brand: "Honda", model: "Civic", year: 2019}}
Retrieves a field from a hash.
Similar to get/3, but raises FluxRedis.Error.t/0 on failure.
Examples
iex> hash_storages = [cars: [:brand, :model]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> car = %{brand: "Honda", model: "Civic", year: 2019}
...> FluxRedis.HashManager.set(:cars, car)
...> FluxRedis.HashManager.get!(:cars, ["Honda", "Civic"])
%{brand: "Honda", model: "Civic", year: 2019}
get_all(hash, opts \\ [])
View Source (since 0.0.1)get_all(atom(), keyword()) :: {:ok, [map()]} | {:error, FluxRedis.Error.t()}
Retrieves all fields in a hash.
Returns {:ok, fields} in case of success or {:error, %FluxRedis.Error{}}
otherwise.
This function always sets :no_reply? option to false.
Parameters
hash- Theatom/0defined inFluxRedishash_storagesapplication configuration.opts-keyword/0of options. CheckFluxRedis.HashManagerfor more information.
Examples
iex> hash_storages = [users: :id]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> users = [%{id: 1, name: "John"}, %{id: 2, name: "Doe"}]
...> FluxRedis.HashManager.set_many(:users, users)
...> FluxRedis.HashManager.get_all(:users)
{:ok, [%{id: 1, name: "John"}, %{id: 2, name: "Doe"}]}
Retrieves all fields in a hash.
Similar to get_all/2, but raises FluxRedis.Error.t/0 on failure.
Examples
iex> hash_storages = [users: :id]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> users = [%{id: 1, name: "John"}, %{id: 2, name: "Doe"}]
...> FluxRedis.HashManager.set_many(:users, users)
...> FluxRedis.HashManager.get_all!(:users)
[%{id: 1, name: "John"}, %{id: 2, name: "Doe"}]
get_many(hash, key_data_list, opts \\ [])
View Source (since 0.0.1)get_many(atom(), key_data_list(), keyword()) :: {:ok, [map()]} | {:error, FluxRedis.Error.t()}
Retrieves one or more fields in a hash.
Returns {:ok, fields} in case of success or {:error, %FluxRedis.Error{}}
otherwise.
This function always sets :no_reply? option to false.
Parameters
hash- Theatom/0defined inFluxRedishash_storagesapplication configuration.key_data_list- Thekey_data_list/0with the values of each key defined inFluxRedishash_storagesapplication configuration.opts-keyword/0with command options. CheckFluxRedis.HashManagerfor more information.
Examples
iex> hash_storages = [animals: [:phylum, :family]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> animals = [
...> %{family: "Canidae", phylum: "Chordata"},
...> %{family: "Felidae", phylum: "Chordata"}
...> ]
...> FluxRedis.HashManager.set_many(:animals, animals)
...> animals_keys = [["Chordata", "Canidae"], ["Chordata", "Felidae"]]
...> FluxRedis.HashManager.get_many(:animals, animals_keys)
{
:ok,
[
%{family: "Canidae", phylum: "Chordata"},
%{family: "Felidae", phylum: "Chordata"}
]
}
get_many!(hash, key_data_list, opts \\ [])
View Source (since 0.0.2)get_many!(atom(), key_data_list(), keyword()) :: [map()]
Retrieves one or more fields in a hash.
Similar to get_many/3, but raises FluxRedis.Error.t/0 on failure.
Examples
iex> hash_storages = [animals: [:phylum, :family]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> animals = [
...> %{family: "Canidae", phylum: "Chordata"},
...> %{family: "Felidae", phylum: "Chordata"}
...> ]
...> FluxRedis.HashManager.set_many(:animals, animals)
...> animals_keys = [["Chordata", "Canidae"], ["Chordata", "Felidae"]]
...> FluxRedis.HashManager.get_many!(:animals, animals_keys)
[
%{family: "Canidae", phylum: "Chordata"},
%{family: "Felidae", phylum: "Chordata"}
]
Retrieves one or more fields that match key values pattern in a hash.
Returns {:ok, fields} in case of success or {:error, %FluxRedis.Error{}}
otherwise.
This function always sets :no_reply? option to false.
Parameters
hash- Theatom/0defined inFluxRedishash_storagesapplication configuration.key_data- Thekey_data/0with the pattern of one or more keys defined inFluxRedishash_storagesapplication configuration.opts-keyword/0with command options. CheckFluxRedis.HashManagerfor more information.
Examples
iex> hash_storages = [animals: [:phylum, :family]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> animals = [
...> %{family: "Canidae", phylum: "Chordata"},
...> %{family: "Felidae", phylum: "Chordata"}
...> ]
...> FluxRedis.HashManager.set_many(:animals, animals)
...> pattern = ["*", "Can*"]
...> FluxRedis.HashManager.get_match(:animals, pattern)
{:ok, [%{family: "Canidae", phylum: "Chordata"}]}
Retrieves one or more fields that match key values pattern in a hash.
Similar to get_match/3, but raises FluxRedis.Error.t/0 on failure.
Examples
iex> hash_storages = [animals: [:phylum, :family]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> animals = [
...> %{family: "Canidae", phylum: "Chordata"},
...> %{family: "Felidae", phylum: "Chordata"}
...> ]
...> FluxRedis.HashManager.set_many(:animals, animals)
...> pattern = ["*", "Can*"]
...> FluxRedis.HashManager.get_match!(:animals, pattern)
[%{family: "Canidae", phylum: "Chordata"}]
Check if field exists in a hash.
Returns {:ok, boolean} in case of success or {:error, %FluxRedis.Error{}}
otherwise.
This function always sets :no_reply? option to false.
Parameters
hash- Theatom/0defined inFluxRedishash_storagesapplication configuration.key_data- Thekey_data/0with the values of each key defined inFluxRedishash_storagesapplication configuration.opts-keyword/0with command options. CheckFluxRedis.HashManagerfor more information.
Examples
iex> hash_storages = [cars: [:brand, :model]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> car = %{brand: "Honda", model: "Civic", year: 2019}
...> FluxRedis.HashManager.set(:cars, car)
...> FluxRedis.HashManager.has(:cars, ["Honda", "Civic"])
{:ok, true}
...> FluxRedis.HashManager.has(:cars, ["Honda", "City"])
{:ok, false}
Check if field exists in a hash.
Similar to has/3, but raises FluxRedis.Error.t/0 on failure.
Examples
iex> hash_storages = [cars: [:brand, :model]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> car = %{brand: "Honda", model: "Civic", year: 2019}
...> FluxRedis.HashManager.set(:cars, car)
...> FluxRedis.HashManager.has?(:cars, ["Honda", "Civic"])
true
...> FluxRedis.HashManager.has?(:cars, ["Honda", "City"])
false
set(hash, data, opts \\ [no_reply?: true])
View Source (since 0.0.1)set(atom(), map(), keyword()) :: :ok | {:ok, :set | :not_changed} | {:error, FluxRedis.Error.t()}
Add or update a field in a hash.
Returns :ok in case of successful request and no_reply? is set to true.
Returns {:ok, :set} or {:ok, :not_changed} in case of success and
no_reply? is set to false.
Returns {:error, %FluxRedis.Error{}} on failure.
By default, the option no_reply? is set to true.
Parameters
hash- Theatom/0defined inFluxRedishash_storagesapplication configuration.data- Amap/0. Must have at least all keys defined inFluxRedishash_storagesapplication configuration.opts-keyword/0with command options. CheckFluxRedis.HashManagerfor more information.
Examples
iex> hash_storages = [cars: [:brand, :model]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> car = %{brand: "Honda", model: "Civic", year: 2019}
...> FluxRedis.HashManager.set(:cars, car, no_reply?: false)
{:ok, :set}
...> FluxRedis.HashManager.set(:cars, car, no_reply?: false)
{:ok, :not_changed}
Add or update a field in a hash.
Similar to set/3, but raises FluxRedis.Error.t/0 on failure.
Examples
iex> hash_storages = [cars: [:brand, :model]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> car = %{brand: "Honda", model: "Civic", year: 2019}
...> FluxRedis.HashManager.set!(:cars, car, no_reply?: false)
:set
...> FluxRedis.HashManager.set!(:cars, car, no_reply?: false)
:not_changed
set_many(hash, data_list, opts \\ [no_reply?: true])
View Source (since 0.0.2)set_many(atom(), [map()], keyword()) :: :ok | {:ok, integer()} | {:error, FluxRedis.Error.t()}
Add or update one or more fields in a hash.
Returns :ok in case of successful request and no_reply? is set to true.
Returns {:ok, amount_set} in case of success and no_reply? is set to
false.
Returns {:error, %FluxRedis.Error{}} on failure.
By default, the option no_reply? is set to true.
Parameters
hash- Theatom/0defined inFluxRedishash_storagesapplication configuration.data_list- Alist/1ofmap/0. Each map Must have at least all keys defined inFluxRedishash_storagesapplication configuration.opts-keyword/0with command options. CheckFluxRedis.HashManagerfor more information.
Examples
iex> hash_storages = [cars: [:brand, :model]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> civic = %{brand: "Honda", model: "Civic", year: 2019}
...> city = %{brand: "Honda", model: "City", year: 2018}
...> alias FluxRedis.HashManager
...> HashManager.set_many(:cars, [civic, city], no_reply?: false)
{:ok, 2}
...> ram = %{brand: "Dodge", model: "Ram", year: 2020}
...> HashManager.set_many(:cars, [city, ram], no_reply?: false)
{:ok, 1}
set_many!(hash, data_list, opts \\ [no_reply?: true])
View Source (since 0.0.2)Add or update one or more fields in a hash.
Similar to set_many/3, but raises FluxRedis.Error.t/0 on failure.
Examples
iex> hash_storages = [cars: [:brand, :model]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> civic = %{brand: "Honda", model: "Civic", year: 2019}
...> city = %{brand: "Honda", model: "City", year: 2018}
...> alias FluxRedis.HashManager
...> HashManager.set_many!(:cars, [civic, city], no_reply?: false)
...> ram = %{brand: "Dodge", model: "Ram", year: 2020}
...> HashManager.set_many!(:cars, [city, ram], no_reply?: false)
1
set_new(hash, data, opts \\ [no_reply?: true])
View Source (since 0.0.2)set_new(atom(), map(), keyword()) :: :ok | {:ok, :set | :not_changed} | {:error, FluxRedis.Error.t()}
Add a field in a hash.
This function does not update a field, use set/3 to update a field.
Returns :ok in case of successful request and no_reply? is set to true.
Returns {:ok, :set} or {:ok, :not_changed} in case of success and
no_reply? is set to false.
Returns {:error, %FluxRedis.Error{}} on failure.
By default, the option no_reply? is set to true.
Parameters
hash- Theatom/0defined inFluxRedishash_storagesapplication configuration.data- Amap/0. Must have at least all keys defined inFluxRedishash_storagesapplication configuration.opts-keyword/0with command options. CheckFluxRedis.HashManagerfor more information.
Examples
iex> hash_storages = [cars: [:brand, :model]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> car = %{brand: "Honda", model: "Civic", year: 2019}
...> FluxRedis.HashManager.set_new(:cars, car, no_reply?: false)
{:ok, :set}
...> FluxRedis.HashManager.set_new(:cars, car, no_reply?: false)
{:ok, :not_changed}
Add a field in a hash.
Similar to set_new/3, but raises FluxRedis.Error.t/0 on failure.
Examples
iex> hash_storages = [cars: [:brand, :model]]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> car = %{brand: "Honda", model: "Civic", year: 2019}
...> FluxRedis.HashManager.set_new!(:cars, car, no_reply?: false)
:set
...> FluxRedis.HashManager.set_new!(:cars, car, no_reply?: false)
:not_changed