作者:痞子343 | 来源:互联网 | 2023-08-29 11:56
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| namespace app\shop\drive;
class Redis {
public $handler;
public function __construct(){
$redis = new \Redis();
$redisCOnf= config('cache.redis');
$redis->connect($redisConf['host'], $redisConf['port']);
$redis->auth($redisConf['password']);
$this->handler = $redis;
}
public function __destruct(){
$this->handler->close();
}
}
|
控制器中
1 2 3 4 5 6 7 8 9 10 11 12 13
| ...
public $redis, $prefix;
protected function _initialize(){
$this->initRedis();
var_dump($this->redis->info()); //出错,redis连接已关闭
}
private function initRedis()
{
$redis = new Redis;
$this->redis = $redis->handler;
var_dump($this->redis->info()); //正常
$this->prefix = config('cache.redis')['prefix'];
} |
1、这是啥原因?
2、有必要手动关闭redis连接吗?