瀏覽代碼

处理redis

panda 5 月之前
父節點
當前提交
8d01a48697
共有 2 個文件被更改,包括 5 次插入7 次删除
  1. 4 4
      application/common/library/token/driver/Redis.php
  2. 1 3
      application/config.php

+ 4 - 4
application/common/library/token/driver/Redis.php

@@ -24,15 +24,15 @@ class Redis extends Driver
 
     /**
      * 构造函数
-     * @param array $options 缓存参数
      * @throws \BadFunctionCallException
      * @access public
      */
-    public function __construct($options = [])
+    public function __construct()
     {
         if (!extension_loaded('redis')) {
             throw new \BadFunctionCallException('not support: redis');
         }
+        $options = config('redis');
         if (!empty($options)) {
             $this->options = array_merge($this->options, $options);
         }
@@ -61,7 +61,7 @@ class Redis extends Driver
     {
         $config = \think\Config::get('token');
         $token = $token ?? ''; // 为兼容 php8
-        return $this->options['tokenprefix'] . hash_hmac($config['hashalgo'], $token, $config['key']);
+        return $this->options['prefix'] . $this->options['tokenprefix'] . hash_hmac($config['hashalgo'], $token, $config['key']);
     }
 
     /**
@@ -71,7 +71,7 @@ class Redis extends Driver
      */
     protected function getUserKey($user_id)
     {
-        return $this->options['userprefix'] . $user_id;
+        return $this->options['prefix'] . $this->options['userprefix'] . $user_id;
     }
 
     /**

+ 1 - 3
application/config.php

@@ -315,9 +315,7 @@ return [
         // 密码
         'password'   => Env::get('redis.REDIS_PASSWORD', ''),
         'select'     => Env::get('redis.REDIS_DB', 15),
-        'timeout'    => Env::get('redis.REDIS_TIMEOUT', 0),//
-        // 默认缓存时常 0为永久
-        'expire'     => Env::get('redis.REDIS_EXPIRE', 0),
+        'timeout'    => Env::get('redis.REDIS_TIMEOUT', 0),
         'persistent' => (bool)Env::get('redis.REDIS_PERSISTENT', false),
         // 缓存前缀
         'prefix'     => Env::get('redis.REDIS_PREFIX', 'c:'),