mirror of
https://github.com/predis/predis.git
synced 2026-08-21 03:32:26 +00:00
Fix DispatcherLoop error with client prefix keys
DispatcherLoop works properly if a client have configured a prefix for the keys or not
This commit is contained in:
@@ -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() : '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user