From 01469e316ec36eaa4bb9259d08fd3b00a6ff8644 Mon Sep 17 00:00:00 2001 From: Peter Membrey Date: Wed, 18 Apr 2012 21:43:38 +0800 Subject: [PATCH 1/3] Updated README to show eredis now supports pattern subscribe --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 906bc668..569f5707 100644 --- a/README.md +++ b/README.md @@ -120,8 +120,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 From 95b7669fa005a902adba2fd3c8b39d6a1b1b81b1 Mon Sep 17 00:00:00 2001 From: Peter Membrey Date: Wed, 18 Apr 2012 22:39:45 +0800 Subject: [PATCH 2/3] Added simple example for pattern subscribe. --- src/eredis_sub.erl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/eredis_sub.erl b/src/eredis_sub.erl index 86b9c1c6..b9b11d0c 100644 --- a/src/eredis_sub.erl +++ b/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). + + From 22e365f1d50dc7fa15011c57b202b3294a5efdb1 Mon Sep 17 00:00:00 2001 From: Peter Membrey Date: Wed, 18 Apr 2012 22:40:16 +0800 Subject: [PATCH 3/3] Updated documentation with example for pattern subscribe --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 569f5707..a431f9d0 100644 --- a/README.md +++ b/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: