浏览代码

Update redis

Jinhui Zhu 7 年之前
父节点
当前提交
ffe166b502
共有 4 个文件被更改,包括 43 次插入24 次删除
  1. 4 0
      Qii/Application.php
  2. 3 2
      Qii/Base/Controller.php
  3. 23 19
      Qii/Base/Dispatcher.php
  4. 13 3
      Qii/Cache/Redis.php

+ 4 - 0
Qii/Application.php

@@ -40,6 +40,10 @@ class Application
      * Qii\Request\Url
      */
     public $request;
+    /**
+     * 分发器
+     */
+    public $dispatcher = null;
 
 	public function __construct()
 	{

+ 3 - 2
Qii/Base/Controller.php

@@ -78,7 +78,8 @@ abstract class Controller
         $this->controllerId = $this->request->controller;
         $this->actionId = $this->request->action;
         $this->language = \Qii\Autoloader\Factory::getInstance('\Qii\Language\Loader');
-        $this->response = \Qii\Autoloader\Factory::getInstance('\Qii\Base\Response');;
+        $this->response = \Qii\Autoloader\Factory::getInstance('\Qii\Base\Response');
+        $this->cache = new \stdClass();
         //载入model
         if ($this->enableDB) {
             $this->enableDB();
@@ -142,7 +143,7 @@ abstract class Controller
             $policy = array_merge($basicPolicy, $policy);
         }
         $loader = new \Qii\Cache\Loader($engine);
-        return $this->cache = $loader->initialization($policy);
+        return $this->cache->$engine = $loader->initialization($policy);
     }
 
     /**

+ 23 - 19
Qii/Base/Dispatcher.php

@@ -8,6 +8,10 @@ class Dispatcher
 {
     public $request;
 
+    public $controllerCls = null;
+
+    public $actionCls = null;
+
     public function __construct()
     {
 
@@ -41,36 +45,36 @@ class Dispatcher
         }
         array_unshift($funcArgs, $controllerName);
         $psr4 = \Qii\Autoloader\Psr4::getInstance();
-        $controllerCls = call_user_func_array(array($psr4, 'loadClass'), $funcArgs);
-        $controllerCls->setRequest($this->request);
-        $controllerCls->controller = $controllerCls;
-        $controllerCls->controllerId = $controller;
-        $controllerCls->actionId = $action;
+        $this->controllerCls = call_user_func_array(array($psr4, 'loadClass'), $funcArgs);
+        $this->controllerCls->setRequest($this->request);
+        $this->controllerCls->controller = $this->controllerCls;
+        $this->controllerCls->controllerId = $controller;
+        $this->controllerCls->actionId = $action;
         $response = null;
         //查看是否设置了当前action的对应关系,如果设置了就走对应关系里边的,否则走当前类中的
-        if ($controllerCls->actions && isset($controllerCls->actions[$action]) && $controllerCls->actions[$action]) {
+        if ($this->controllerCls->actions && isset($this->controllerCls->actions[$action]) && $this->controllerCls->actions[$action]) {
             $actionArgs = array();
-            $actionArgs[] = $controllerCls->actions[$action];
-            $actionCls = call_user_func_array(array($psr4, 'loadClass'), $actionArgs);
-            $actionCls->setRequest($this->request);
-            $actionCls->controller = $controllerCls;
-            $actionCls->actionId = $action;
-            $actionCls->controllerId = $controllerCls->controllerId;
+            $actionArgs[] = $this->controllerCls->actions[$action];
+            $this->actionCls = call_user_func_array(array($psr4, 'loadClass'), $actionArgs);
+            $this->actionCls->setRequest($this->request);
+            $this->actionCls->controller = $this->controllerCls;
+            $this->actionCls->actionId = $action;
+            $this->actionCls->controllerId = $this->controllerCls->controllerId;
             //支持多个action对应到同一个文件,如果对应的文件中存在指定的方法就直接调用
-            if (method_exists($actionCls, $action . Register::get(Consts::APP_DEFAULT_ACTION_SUFFIX))) {
-                $actionCls->response = $response = call_user_func_array(array($actionCls, $action. Register::get(Consts::APP_DEFAULT_ACTION_SUFFIX)), $funcArgs);
+            if (method_exists($this->actionCls, $action . Register::get(Consts::APP_DEFAULT_ACTION_SUFFIX))) {
+                $this->actionCls->response = $response = call_user_func_array(array($this->actionCls, $action. Register::get(Consts::APP_DEFAULT_ACTION_SUFFIX)), $funcArgs);
             }
-            if (!method_exists($actionCls, 'run')) {
-                throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1101, $controllerCls->actions[$action] . '->run'), __LINE__);
+            if (!method_exists($this->actionCls, 'run')) {
+                throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1101, $this->controllerCls->actions[$action] . '->run'), __LINE__);
             }
-            $response = call_user_func_array(array($actionCls, 'run'), $funcArgs);
+            $response = call_user_func_array(array($this->actionCls, 'run'), $funcArgs);
         } else {
             array_shift($funcArgs);
             $actionName = $action . Register::get(Consts::APP_DEFAULT_ACTION_SUFFIX);
-            if (!method_exists($controllerCls, $actionName) && !method_exists($controllerCls, '__call')) {
+            if (!method_exists($this->controllerCls, $actionName) && !method_exists($this->controllerCls, '__call')) {
                 throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1101, $controller . '->' . $actionName), __LINE__);
             }
-            $controllerCls->response = $response = call_user_func_array(array($controllerCls, $actionName), $funcArgs);
+            $this->controllerCls->response = $response = call_user_func_array(array($this->controllerCls, $actionName), $funcArgs);
         }
         return $response;
     }

+ 13 - 3
Qii/Cache/Redis.php

@@ -52,10 +52,10 @@ class Redis implements Intf
      */
     public function set($id, $data, array $policy = null)
     {
-        if (!isset($policy['life_time'])) $policy['life_time'] = $this->_default_policy['life_time'];
+        if (!isset($policy['life_time'])) $policy['life_time'] = $this->policy['life_time'];
         try {
             $this->redis->hMset($id, $data);
-            if ($policy['lift_time'] > 0) {
+            if (isset($policy['life_time']) && $policy['life_time'] > 0) {
                 $this->redis->setTimeout($id, $policy['life_time']);
             }
         } catch (\CredisException $e) {
@@ -66,13 +66,23 @@ class Redis implements Intf
     /**
      * 获取指定key的数据
      */
-    public function get($id)
+    public function hGet($id)
     {
         if ($this->redis->exists($id)) {
             return $this->redis->hGetAll($id);
         }
         return null;
     }
+    /**
+     * 获取指定key的数据
+     */
+    public function get($id)
+    {
+        if ($this->redis->exists($id)) {
+            return $this->redis->get($id);
+        }
+        return null;
+    }
 
     /**
      * 删除指定key的数据