Events.php要引入TP里面 緩存cache::set 怎么引入有方法嗎
看他們文檔,有用法
https://github.com/top-think/think-cache
安裝:
composer require topthink/think-cache
然后可以在onWorkerStart里配置Cache,然后就可以在onMessage onXXX里使用了
use think\facade\Cache;
class Events
{
public static function onWorkerStart()
{
Cache::config([
'default' => 'file',
'stores' => [
'file' => [
'type' => 'File',
// 緩存保存目錄
'path' => './cache/',
// 緩存前綴
'prefix' => '',
// 緩存有效期 0表示永久緩存
'expire' => 0,
],
'redis' => [
'type' => 'redis',
'host' => '127.0.0.1',
'port' => 6379,
'prefix' => '',
'expire' => 0,
],
],
]);
}
public function onMessage($client_id, $data)
{
Cache::get('val');
}
}