yggdrasil v3.2.1 Yggdrasil.Subscriber.Adapter.Redis View Source

Yggdrasil subscriber adapter for Redis. The name of the channel must be a binary e.g:

Subscription to channel:

iex(1)> alias Yggdrasil.Channel
iex(2)> sub_channel = %Channel{
...(2)>   name: "redis_channel",
...(2)>   adapter: Yggdrasil.Subscriber.Adapter.Redis
...(2)> }
iex(3)> Yggdrasil.subscribe(sub_channel)
:ok
iex(4)> flush()
{:Y_CONNECTED, %Channel{name: "redis_channel", (...)}}

Publishing message:

iex(5)> pub_channel = %Channel{
...(5)>   name: "redis_channel",
...(5)>   adapter: Yggdrasil.Publisher.Adapter.Redis
...(5)> }
iex(6)> Yggdrasil.publish(pub_channel, "message")
:ok

Subscriber receiving message:

iex(7)> flush()
{:Y_EVENT, %Channel{name: "redis_channel", (...)}, "message"}

Instead of having sub_channel and pub_channel, the hibrid channel can be used. For the previous example we can do the following:

iex(1)> alias Yggdrasil.Channel
iex(2)> channel = %Channel{name: "redis_channel", adapter: :redis}
iex(3)> Yggdrasil.subscribe(channel)
:ok
iex(4)> flush()
{:Y_CONNECTED, %Channel{name: "redis_channel", (...)}}
iex(5)> Yggdrasil.publish(channel, "message")
:ok
iex(6)> flush()
{:Y_EVENT, %Channel{name: "redis_channel", (...)}, "message"}

Link to this section Summary

Functions

Starts a Redis distributor adapter in a channel with some distributor publisher and optionally GenServer options

Stops the Redis adapter with its pid

Link to this section Functions

Link to this function start_link(channel, publisher, options \\ []) View Source

Starts a Redis distributor adapter in a channel with some distributor publisher and optionally GenServer options.

Stops the Redis adapter with its pid.