From 6cd124cc593ea4fb9570e36d9569162ddb220269 Mon Sep 17 00:00:00 2001 From: Eloi Poch Date: Sat, 20 Apr 2013 13:02:17 +0200 Subject: [PATCH] Fix DispatcherLoop error with client prefix keys DispatcherLoop works properly if a client have configured a prefix for the keys or not --- lib/Predis/PubSub/DispatcherLoop.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/Predis/PubSub/DispatcherLoop.php b/lib/Predis/PubSub/DispatcherLoop.php index e2455a00..d6f4ae20 100644 --- a/lib/Predis/PubSub/DispatcherLoop.php +++ b/lib/Predis/PubSub/DispatcherLoop.php @@ -96,8 +96,10 @@ class DispatcherLoop */ public function attachCallback($channel, $callback) { + $callbackName = $this->getPrefixKeys() . $channel; + $this->validateCallback($callback); - $this->callbacks[$channel] = $callback; + $this->callbacks[$callbackName] = $callback; $this->pubSubContext->subscribe($channel); } @@ -108,8 +110,10 @@ class DispatcherLoop */ public function detachCallback($channel) { - if (isset($this->callbacks[$channel])) { - unset($this->callbacks[$channel]); + $callbackName = $this->getPrefixKeys() . $channel; + + if (isset($this->callbacks[$callbackName])) { + unset($this->callbacks[$callbackName]); $this->pubSubContext->unsubscribe($channel); } } @@ -148,4 +152,16 @@ class DispatcherLoop { $this->pubSubContext->closeContext(); } + + /** + * Return the prefix of the keys + * + * @return string + */ + protected function getPrefixKeys() + { + $prefix = $this->client->getOptions()->prefix; + + return $prefix ? $prefix->getPrefix() : ''; + } }