From 897c217fe333921a6ad32b80e51267dd3cea6c8e Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 12 Feb 2011 14:03:58 +0100 Subject: [PATCH] Backported changes from the mainline library to the PHP 5.2 branch (up to commit ca422b0) --- CHANGELOG | 9 ++++++++- VERSION | 2 +- lib/Predis.php | 25 +++++++++++++++++++++---- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 56837557..1d5c1dcd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,14 @@ -v0.6.4 (2011-??-??) +v0.6.4 (2011-02-12) * Various performance improvements (15% ~ 25%) especially when dealing with long multibulk replies or when using clustered connections. + * Added the "on_retry" option to Predis_MultiExecBlock that can be used to + specify an external callback (or any callable object) that gets invoked + whenever a transaction is aborted by the server. + + * Added inline (p)subscribtion via options when initializing an instance of + Predis_PubSubContext. + v0.6.3 (2011-01-01) * New commands available in the Redis v2.2 profile (dev): - Strings: SETRANGE, GETRANGE, SETBIT, GETBIT diff --git a/VERSION b/VERSION index ba6a53c9..d2b13eb6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.6.4-dev +0.6.4 diff --git a/lib/Predis.php b/lib/Predis.php index 1eef0a58..62c4dd0a 100644 --- a/lib/Predis.php +++ b/lib/Predis.php @@ -294,8 +294,8 @@ class Predis_Client { return $transBlock !== null ? $multi->execute($transBlock) : $multi; } - public function pubSubContext() { - return new Predis_PubSubContext($this); + public function pubSubContext(Array $options = null) { + return new Predis_PubSubContext($this, $options); } } @@ -1060,12 +1060,16 @@ class Predis_PubSubContext implements Iterator { const STATUS_SUBSCRIBED = 0x0010; const STATUS_PSUBSCRIBED = 0x0100; - private $_redisClient, $_position; + private $_redisClient, $_position, $_options; - public function __construct(Predis_Client $redisClient) { + public function __construct(Predis_Client $redisClient, Array $options = null) { $this->checkCapabilities($redisClient); + $this->_options = isset($options) ? $options : array(); $this->_redisClient = $redisClient; $this->_statusFlags = self::STATUS_VALID; + + $this->genericSubscribeInit('subscribe'); + $this->genericSubscribeInit('psubscribe'); } public function __destruct() { @@ -1089,6 +1093,19 @@ class Predis_PubSubContext implements Iterator { } } + private function genericSubscribeInit($subscribeAction) { + if (isset($this->_options[$subscribeAction])) { + if (is_array($this->_options[$subscribeAction])) { + foreach ($this->_options[$subscribeAction] as $subscription) { + $this->$subscribeAction($subscription); + } + } + else { + $this->$subscribeAction($this->_options[$subscribeAction]); + } + } + } + private function isFlagSet($value) { return ($this->_statusFlags & $value) === $value; }