Permalink
Browse files

Merge pull request #27 from pmembrey/master

Added documentation for pattern subscribe and example functions
  • Loading branch information...
2 parents 12d700f + 22e365f commit 06ce72405b560785c400318405c727d84e2abd34 @knutin knutin committed Apr 18, 2012
Showing with 30 additions and 2 deletions.
  1. +12 −2 README.md
  2. +18 −0 src/eredis_sub.erl
View
14 README.md
@@ -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:
@@ -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
View
18 src/eredis_sub.erl
@@ -18,6 +18,8 @@
-export([receiver/1, sub_example/0, pub_example/0]).
+-export([psub_example/0,ppub_example/0]).
+
%%
%% PUBLIC API
%%
@@ -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.