Events.php要引入TP里面 缓存cache::set 怎么引入有方法吗

bl2020

Events.php要引入TP里面 缓存cache::set 怎么引入有方法吗

1795 1 1
1个回答

six

看他们文档,有用法
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');
    }
}
年代过于久远,无法发表回答
🔝