在hyperf中如何使用redis缓存
1、首先修改.env文件配置redis服务器参数
```
REDIS_HOST=127.0.0.1
REDIS_AUTH=(null)
REDIS_PORT=6379
REDIS_DB=1
```
2、修改Controller文件
```
request->input('user', 'Hyperf');
$method = $this->request->getMethod();
$container = ApplicationContext::getContainer();
$this->redis = $container->get(\Redis::class);
$this->redis->set('name','value');
$user.=$this->redis->get('name');
return [
'method' => $method,
'message' => "Hello {$user}.",
];
}
}
```
3、打开config/routes.php,添加路由
```
Router::get('/redis', 'App\Controller\RedisController@index');
```