_client = $client; } /** * Gets the redis client * @return Redis the redis client */ public function getClient() { if ($this->_client === null) { $this->_client = new Redis; $this->_client->connect($this->hostname, $this->port); if (isset($this->password)) { if ($this->_client->auth($this->password) === false) { throw new CException('Redis authentication failed!'); } } $this->_client->setOption(Redis::OPT_PREFIX, $this->prefix); $this->_client->select($this->database); } return $this->_client; } /** * Returns a property value based on its name. * Do not call this method. This is a PHP magic method that we override * to allow using the following syntax to read a property *
* $value=$component->propertyName; ** @param string $name the property name * @return mixed the property value * @throws CException if the property is not defined * @see __set */ public function __get($name) { $getter='get'.$name; if (property_exists($this->getClient(),$name)) { return $this->getClient()->{$name}; } elseif(method_exists($this->getClient(),$getter)) { return $this->$getter(); } return parent::__get($name); } /** * Sets value of a component property. * Do not call this method. This is a PHP magic method that we override * to allow using the following syntax to set a property *
* $this->propertyName=$value; ** @param string $name the property name * @param mixed $value the property value * @return mixed * @throws CException if the property is not defined or the property is read only. * @see __get */ public function __set($name,$value) { $setter='set'.$name; if (property_exists($this->getClient(),$name)) { return $this->getClient()->{$name} = $value; } elseif(method_exists($this->getClient(),$setter)) { return $this->getClient()->{$setter}($value); } return parent::__set($name,$value); } /** * Checks if a property value is null. * Do not call this method. This is a PHP magic method that we override * to allow using isset() to detect if a component property is set or not. * @param string $name the property name * @return boolean */ public function __isset($name) { $getter='get'.$name; if (property_exists($this->getClient(),$name)) { return true; } elseif (method_exists($this->getClient(),$getter)) { return true; } return parent::__isset($name); } /** * Sets a component property to be null. * Do not call this method. This is a PHP magic method that we override * to allow using unset() to set a component property to be null. * @param string $name the property name or the event name * @throws CException if the property is read only. * @return mixed */ public function __unset($name) { $setter='set'.$name; if (property_exists($this->getClient(),$name)) { $this->getClient()->{$name} = null; } elseif(method_exists($this,$setter)) { $this->$setter(null); } else { parent::__unset($name); } } /** * Calls a method on the redis client with the given name. * Do not call this method. This is a PHP magic method that we override to * allow a facade in front of the redis object. * @param string $name the name of the method to call * @param array $parameters the parameters to pass to the method * @return mixed the response from the redis client */ public function __call($name, $parameters) { return call_user_func_array(array($this->getClient(),$name),$parameters); } }