redix_stream v0.2.0 Redix.Stream

Redix.Stream exposes an API for producing to redis streams, as well consuming from those streams (via a process called a Consumer).

Link to this section Summary

Functions

Provides a supervisable specification for a consumer which consumes from the given topic or topics

Produces a new single message into a Redis stream

Link to this section Types

Link to this type handler()
handler() :: {module(), atom(), [any()]}
Link to this type redix()
redix() :: pid() | atom()

Link to this section Functions

Link to this function consumer_spec(redix, stream, callback, opts \\ [])
consumer_spec(redix(), t(), function() | handler(), keyword()) ::
  Supervisor.child_spec()

Provides a supervisable specification for a consumer which consumes from the given topic or topics.

Examples

iex> Redix.Stream.consumer_spec(:redix, "topic", fn msg -> msg end)[:id]
Redix.Stream.ConsumerSup

iex> Redix.Stream.consumer_spec(:redix, "topic", {Module, :function, [:arg1, :arg2]}, sup_id: MyConsumer)[:id]
MyConsumer

iex> Redix.Stream.consumer_spec(:redix, "topic", {Module, :function, [:arg1, :arg2]}, sup_restart: :transient)[:restart]
:transient
Link to this function produce(redix, stream, key_values)
produce(redix(), t(), %{optional(String.t()) => any()}) ::
  {:ok, String.t()} | {:error, any()}

Produces a new single message into a Redis stream.

Note: For values which are not strings, each of those values will be

  converted into a string via [`to_string/1`](https://hexdocs.pm/elixir/Kernel.html#to_string/1).

Examples

iex> {:ok, msg_id} = Redix.Stream.produce(:redix, "topic", %{"temperature" => 55})
iex> Enum.count(String.split(msg_id, "-"))
2