Skip to content

Commit

Permalink
Merge pull request #27 from pmembrey/master
Browse files Browse the repository at this point in the history
Added documentation for pattern subscribe and example functions
  • Loading branch information
knutin committed Apr 18, 2012
2 parents 12d700f + 22e365f commit 06ce724
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
14 changes: 12 additions & 2 deletions README.md
Expand Up @@ -52,6 +52,15 @@ Pubsub:
2> redis_sub:pub_example().
received {message,<<"foo">>,<<"bar">>,<0.34.0>}

Pattern Subscribe:

1> eredis_sub:psub_example().
received {subscribed,<<"foo*">>,<0.33.0>}
{<0.33.0>,<0.36.0>}
2> eredis_sub:ppub_example().
received {pmessage,<<"foo*">>,<<"foo123">>,<<"bar">>,<0.33.0>}
ok
3>

EUnit tests:

Expand Down Expand Up @@ -120,8 +129,9 @@ Subscriptions are managed using `eredis_sub:subscribe/2` and
subscription, a message is sent to the controlling process for each
channel.

For now, channel patterns are not supported, but it is relatively easy
to add support. Patches are welcome :)
eredis also supports Pattern Subscribe using `eredis_sub:psubscribe/2`
and `eredis_sub:unsubscribe/2`. As with normal subscriptions, a message
is sent to the controlling process for each channel.

## AUTH and SELECT

Expand Down
18 changes: 18 additions & 0 deletions src/eredis_sub.erl
Expand Up @@ -18,6 +18,8 @@

-export([receiver/1, sub_example/0, pub_example/0]).

-export([psub_example/0,ppub_example/0]).

%%
%% PUBLIC API
%%
Expand Down Expand Up @@ -161,7 +163,23 @@ sub_example() ->
end),
{Sub, Receiver}.

psub_example() ->
{ok, Sub} = start_link(),
Receiver = spawn_link(fun () ->
controlling_process(Sub),
psubscribe(Sub, [<<"foo*">>]),
receiver(Sub)
end),
{Sub, Receiver}.

pub_example() ->
{ok, P} = eredis:start_link(),
eredis:q(P, ["PUBLISH", "foo", "bar"]),
eredis_client:stop(P).

ppub_example() ->
{ok, P} = eredis:start_link(),
eredis:q(P, ["PUBLISH", "foo123", "bar"]),
eredis_client:stop(P).


0 comments on commit 06ce724

Please sign in to comment.