{$connection}; } $this->_connection = $connection; } /** * Gets the redis connection to use for caching * @return ARedisConnection */ public function getConnection() { if ($this->_connection === null) { if (!isset(Yii::app()->redis)) { throw new CException(get_class($this)." expects a 'redis' application component"); } $this->_connection = Yii::app()->redis; } return $this->_connection; } /** * Stores or broadcasts log messages via redis. * @param array $logs list of log messages */ protected function processLogs($logs) { $redis = $this->getConnection()->getClient(); if (function_exists("json_encode")) { $useCJSON = false; } else { $useCJSON = true; } foreach($logs as $log) { $item = array( "level" => $log[1], "category" => $log[2], "time" => $log[3], "message" => $log[0], ); if ($useCJSON) { $json = CJSON::encode($item); } else { $json = json_encode($item); } if ($this->useChannel) { $redis->publish($this->redisKey, $json); } else { $redis->zAdd($this->redisKey,$log[3],$json); } } } }