Skip to content

Latest commit

 

History

History
263 lines (167 loc) · 7.75 KB

eredis_sub.md

File metadata and controls

263 lines (167 loc) · 7.75 KB

Module eredis_sub

Erlang PubSub Redis client.

Data Types


channel() = binary()

option() = {host, string()} | {port, integer()} | {database, string()} | {password, string()} | {reconnect_sleep, eredis:reconnect_sleep()} | {max_queue_size, integer() | infinity} | {queue_behaviour, drop | exit}

server_args() = [option()]

Function Index

ack_message/1 Acknowledge the receipt of a pubsub message.
channels/1 Returns the channels the given client is currently subscribing to.
controlling_process/1Equivalent to controlling_process(Client, self()).
controlling_process/2Equivalent to controlling_process(Client, Pid, 5000).
controlling_process/3.
psubscribe/2 Pattern subscribe to the given channels.
punsubscribe/2 Pattern unsubscribe to the given channels.
start_link/0Equivalent to start_link([]).
start_link/1 Start a PubSub Redis client.
start_link/3Equivalent to start_link(Host, Port, Password, 100, infinity, drop).
start_link/6 Start a PubSub Redis client.
stop/1 Stop the PubSub Redis client.
subscribe/2 Subscribe to the given channels.
unsubscribe/2 Unsubscribe to the given channels.

Function Details

ack_message/1


ack_message(Client::pid()) -> ok

Acknowledge the receipt of a pubsub message. each pubsub message must be acknowledged before the next one is received

channels/1


channels(Client::pid()) -> [channel()]

Returns the channels the given client is currently subscribing to. Note: this list is based on the channels at startup and any channel added during runtime. It might not immediately reflect the channels Redis thinks the client is subscribed to.

controlling_process/1


controlling_process(Client::pid()) -> ok

Equivalent to controlling_process(Client, self()).

controlling_process/2


controlling_process(Client::pid(), Pid::pid()) -> ok

Equivalent to controlling_process(Client, Pid, 5000).

controlling_process/3


controlling_process(Client::pid(), Pid::pid(), Timeout::integer()) -> ok

Make the given process (pid) the controlling process subscriber with the given Timeout.

Thecontrolling process received pubsub-related messages, of which there are three kinds. In each message, the pid refers to the eredis client process.

  • {message, Channel :: binary(), Message :: binary(), pid()} : This is sent for each pubsub message received by the client.

  • {pmessage, Pattern :: binary(), Channel :: binary(), Message :: binary(), pid()} : This is sent for each pattern pubsub message received by the client.

  • {dropped, NumMessages :: integer(), pid()} : If the queue reaches the max size as specified in start_link and the behaviour is to drop messages, this message is sent when the queue is flushed.

  • {subscribed, Channel :: binary(), pid()} : When using eredis_sub:subscribe(pid()), this message will be sent for each channel Redis aknowledges the subscription. The opposite, 'unsubscribed' is sent when Redis aknowledges removal of a subscription.

  • {eredis_disconnected, pid()} : This is sent when the eredis client is disconnected from redis.

  • {eredis_connected, pid()} : This is sent when the eredis client reconnects to redis after an existing connection was disconnected.

Any message of the form {message, _, _, _} must be acknowledged before any subsequent message of the same form is sent. This prevents the controlling process from being overrun with redis pubsub messages. @see ack_message/1.

psubscribe/2


psubscribe(Client::pid(), Channels::[channel()]) -> ok

Pattern subscribe to the given channels. Returns immediately. The result will be delivered to the controlling process as any other message. Delivers {subscribed, Channel :: binary(), pid()}

punsubscribe/2


punsubscribe(Client::pid(), Channels::[channel()]) -> ok

Pattern unsubscribe to the given channels. Returns immediately.

start_link/0


start_link() -> {ok, Pid::pid()} | {error, Reason::term()}

Equivalent to start_link([]).

start_link/1


start_link(Args::server_args()) -> {ok, Pid::pid()} | {error, Reason::term()}

Start a PubSub Redis client

start_link/3


start_link(Host::list(), Port::integer(), Password::list()) -> {ok, Pid::pid()} | {error, Reason::term()}

Equivalent to start_link(Host, Port, Password, 100, infinity, drop).

start_link/6


start_link(Host::list(), Port::integer(), Password::list(), ReconnectSleep::integer() | no_reconnect, MaxQueueSize::integer() | infinity, QueueBehaviour::drop | exit) -> {ok, Pid::pid()} | {error, Reason::term()}

Start a PubSub Redis client

stop/1


stop(Client::pid()) -> ok

Stop the PubSub Redis client

subscribe/2


subscribe(Client::pid(), Channels::[channel()]) -> ok

Subscribe to the given channels. Returns immediately. The result will be delivered to the controlling process as any other message. Delivers {subscribed, Channel :: binary(), pid()}

unsubscribe/2


unsubscribe(Client::pid(), Channels::[channel()]) -> ok

Unsubscribe to the given channels. Returns immediately.