如何用hyperf来操作session
>安装
```
composer require hyperf/session
php bin/hyperf.php vendor:publish hyperf/session
```
>配置 Session 中间件
修改config/autoload/middlewares.php
```
[
\Hyperf\Session\Middleware\SessionMiddleware::class,
],
];
```
>配置储存驱动
修改config/autoload/session.php
```
Handler\RedisHandler::class, //改为文件则为FileHandler
'options' => [
'connection' => 'default',
'path' => BASE_PATH . '/runtime/session',
'gc_maxlifetime' => 1200,
'session_name' => 'HYPERF_SESSION_ID',
'domain' => null,
'cookie_lifetime' => 5 * 60 * 60,
],
];
```
创建controller文件
```
session 来使用
$sessionId = $this->session->getId();
//return $sessionId;
//$this->session->set('foo', 'bar');
//$data = $this->session->all();
return $this->session->get('foo');
}
}
```
然后打开redis