Flux Redis v0.0.2 FluxRedis.PipelineManager View Source

Manage multiple commands for a single request.

Command modules

The functions of this module accepts a list/1 of tuple/0 with command/0 and parser/0, both are automatically generated by the following modules:

Pipeline Options

  • :as_transaction? - If false, the request will not be handled as a transaction. Defaults to false. Accepts boolean/0. For more information, please check transactions or pipeling? section from Redix module.

  • :no_reply? - If true, the function returns :ok after successfully send the request to Redis. Defaults to false. Accepts boolean/0.

  • :timeout - Milliseconds to wait for a request sending. Defaults to 5_000. Accepts integer/0 or :infinity.

Link to this section Summary

Types

Command specs generated by one of FluxRedis commands modules.

Parser function generated by one of the FluxRedis commands modules.

Result received after a Redix request.

Functions

Execute one or more commands in a single request.

Execute one or more commands in a single request.

Link to this section Types

Link to this type

command()

View Source
command() :: list()

Command specs generated by one of FluxRedis commands modules.

Link to this type

parser()

View Source
parser() :: (redix_data() -> any())

Parser function generated by one of the FluxRedis commands modules.

Link to this type

redix_data()

View Source
redix_data() :: nil | String.t() | integer() | Redix.Error.t() | [redix_data()]

Result received after a Redix request.

Link to this section Functions

Link to this function

pipeline(pipeline_payload, opts \\ [])

View Source (since 0.0.2)
pipeline([{command(), parser()}], keyword()) ::
  :ok | {:ok, [any()]} | {:error, FluxRedis.Error.t()}

Execute one or more commands in a single request.

Returns :ok in case of successful request and no_reply? is set to true.

Returns {:ok, results} in case of successful request and :no_reply? is set to false, where each result is defined according to the parser/0 or FluxRedis.Error.t/0 if the command failed to be processed.

Returns {:error, %FluxRedis.Error{}} if request failed to reach Redis.

Examples

iex> hash_storages = [
...>   animals: [:phylum, :family],
...>   cars: [:brand, :model],
...>   users: :id
...> ]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> animals = [
...>   %{family: "Canidae", phylum: "Chordata"},
...>   %{family: "Felidae", phylum: "Chordata"}
...> ]
...> car = %{brand: "Honda", model: "Civic", year: 2019}
...> users = [%{id: 1, name: "John"}, %{id: 2, name: "Doe"}]
...> pipeline_payload = [
...>   FluxRedis.HashManager.Commands.set_many!(:animals, animals)
...>   FluxRedis.HashManager.Commands.set!(:cars, car)
...>   FluxRedis.HashManager.Commands.set_many!(:users, users)
...>   FluxRedis.HashManager.Commands.delete(:users, 1)
...>   FluxRedis.HashManager.Commands.count(:animals)
...> ]
...> FluxRedis.PipelineManager.pipeline(pipeline_payload)
{:ok, [2, :set, 2, :ok, 2]}
Link to this function

pipeline!(pipeline_payload, opts \\ [])

View Source (since 0.0.2)
pipeline!([{command(), parser()}], keyword()) :: :ok | [any()]

Execute one or more commands in a single request.

Similar to pipeline/2, but raises FluxRedis.Error.t/0 on failure ( either from a command or from the request itself).

Examples

iex> hash_storages = [
...>   animals: [:phylum, :family],
...>   cars: [:brand, :model],
...>   users: :id
...> ]
...> Application.put_env(:flux_redis, :hash_storages, hash_storages)
...> animals = [
...>   %{family: "Canidae", phylum: "Chordata"},
...>   %{family: "Felidae", phylum: "Chordata"}
...> ]
...> car = %{brand: "Honda", model: "Civic", year: 2019}
...> users = [%{id: 1, name: "John"}, %{id: 2, name: "Doe"}]
...> pipeline_payload = [
...>   FluxRedis.HashManager.Commands.set_many!(:animals, animals)
...>   FluxRedis.HashManager.Commands.set!(:cars, car)
...>   FluxRedis.HashManager.Commands.set_many!(:users, users)
...>   FluxRedis.HashManager.Commands.delete(:users, 1)
...>   FluxRedis.HashManager.Commands.count(:animals)
...> ]
...> FluxRedis.PipelineManager.pipeline!(pipeline_payload)
[2, :set, 2, :ok, 2]