ソースを参照

Fixed: redis cache bugs

Zhu Jinhui 7 年 前
コミット
45a7ddfe22

+ 1 - 1
Qii/Autoloader/Import.php

@@ -67,7 +67,7 @@ class Import
      * 载入文件夹中所有文件
      *
      * @param string $dir 目录
-     * @throws Qii_Exceptions_FileNotFound
+     * @throws Qii\Exceptions\FileNotFound
      */
     public static function requireByDir($dir)
     {

+ 5 - 6
Qii/Cache/Redis.php

@@ -19,7 +19,7 @@ class Redis implements Intf
          * 缓存服务器配置,参看$_default_server
          * 允许多个缓存服务器
          */
-        'servers' => array('127.0.0.1:6379'),
+        'servers' => array(['host' => '127.0.0.1', 'port' => '6379']),
 
         /**
          * 缓存有效时间
@@ -35,17 +35,16 @@ class Redis implements Intf
             throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1006), __LINE__);
         }
 
+
         if (!empty($policy)) {
             $this->policy = array_merge($this->policy, $policy);
         }
 
         $redisServer = array();
-
         foreach ($this->policy['servers'] AS $value) {
-            $host = explode(':', $value);
-            $redisServer[] = array('host' => $host[0], 'port' => $host[1]);
+            $redisServer[] = array('host' => $value['host'], 'port' => $host['port']);
         }
-        $this->redis = new \Redis\Credis\Cluster($redisServer, 128);
+        $this->redis = new \Qii\Cache\Redis\Cluster($redisServer, 128);
     }
 
     /**
@@ -60,7 +59,7 @@ class Redis implements Intf
                 $this->redis->setTimeout($id, $policy['life_time']);
             }
         } catch (\CredisException $e) {
-            throw new Errors(\Qii::i(-1, $e->getMessage()), __LINE__);
+            throw new \Qii\Exceptions\Errors(\Qii::i(-1, $e->getMessage()), __LINE__);
         }
     }
 

+ 4 - 3
Qii/Cache/Redis/Client.php

@@ -1,4 +1,5 @@
 <?php
+namespace Qii\Cache\Redis;
 /**
  * Credis_Client (a fork of Redisent)
  *
@@ -25,7 +26,7 @@ if (!defined('CRLF')) define('CRLF', sprintf('%s%s', chr(13), chr(10)));
 /**
  * Credis-specific errors, wraps native Redis errors
  */
-class CredisException extends Exception
+class CredisException extends \Exception
 {
 
 	const CODE_TIMED_OUT = 1;
@@ -149,7 +150,7 @@ class CredisException extends Exception
  * @method string|int|array|bool eval(string $script, array $keys = NULL, array $args = NULL)
  * @method string|int|array|bool evalSha(string $script, array $keys = NULL, array $args = NULL)
  */
-class Redis_Credis_Client
+class Client
 {
 
 	const TYPE_STRING = 'string';
@@ -437,7 +438,7 @@ class Redis_Credis_Client
 			try {
 				$result = $this->standalone ? fclose($this->redis) : $this->redis->close();
 				$this->connected = FALSE;
-			} catch (Exception $e) {
+			} catch (\Exception $e) {
 				; // Ignore exceptions on close
 			}
 		}

+ 3 - 2
Qii/Cache/Redis/Cluster.php

@@ -1,4 +1,5 @@
 <?php
+namespace Qii\Cache\Redis;
 /**
  * Credis, a Redis interface for the modest
  *
@@ -13,7 +14,7 @@
 /**
  * A generalized Credis_Client interface for a cluster of Redis servers
  */
-class Redis_Credis_Cluster
+class Cluster
 {
 
 	/**
@@ -68,7 +69,7 @@ class Redis_Credis_Cluster
 		$this->ring = array();
 		$clientNum = 0;
 		foreach ($servers as $server) {
-			$client = new Redis_Credis_Client($server['host'], $server['port'], isset($server['timeout']) ? $server['timeout'] : 2.5, isset($server['persistent']) ? $server['persistent'] : '');
+			$client = new \Qii\Cache\Redis\Client($server['host'], $server['port'], isset($server['timeout']) ? $server['timeout'] : 2.5, isset($server['persistent']) ? $server['persistent'] : '');
 			$this->clients[] = $client;
 			if (isset($server['alias'])) {
 				$this->aliases[$server['alias']] = $client;