lizhen_gitee 1 anno fa
parent
commit
5c5d3f2f60

+ 16 - 2
application/common/library/token/driver/Redis.php

@@ -18,8 +18,8 @@ class Redis extends Driver
         'timeout'     => 0,
         'expire'      => 0,
         'persistent'  => false,
-        'userprefix'  => 'up:',
-        'tokenprefix' => 'tp:',
+        'userprefix'  => 'gg_up:',
+        'tokenprefix' => 'gg_tp:',
     ];
 
     /**
@@ -30,6 +30,12 @@ class Redis extends Driver
      */
     public function __construct($options = [])
     {
+        $redis_config = config('redis');
+        $this->options['host']     = $redis_config['host'];
+        $this->options['port']     = $redis_config['port'];
+        $this->options['password'] = $redis_config['redis_pwd'];
+        $this->options['select']   = $redis_config['redis_selectdb'];
+
         if (!extension_loaded('redis')) {
             throw new \BadFunctionCallException('not support: redis');
         }
@@ -106,6 +112,14 @@ class Redis extends Driver
      */
     public function get($token)
     {
+        //方便测试
+        if(strpos($token,'testuid_') !== false && config('app_debug') === true){
+            $uid = substr($token,8);
+            return [
+                'user_id' => intval($uid),
+            ];
+        }
+        //方便测试
         $key = $this->getEncryptedToken($token);
         $value = $this->handler->get($key);
         if (is_null($value) || false === $value) {

+ 1 - 1
application/config.php

@@ -247,7 +247,7 @@ return [
     // +----------------------------------------------------------------------
     'token'                  => [
         // 驱动方式
-        'type'     => 'Mysql',
+        'type'     => 'Redis',
         // 缓存前缀
         'key'      => 'i3d6o32wo8fvs1fvdpwens',
         // 加密方式