Laravel Telescope 未监听 Redis
最近新建一个5.8的项目,调用了Redis,但是在Telescope界面刷新了好几次,在Redis那里一直无数据,后来看了下源码,发现Telescope监听的是Redis的CommandExecuted:
public function register($app)
{
$app['events']->listen(CommandExecuted::class, [$this, 'recordCommand']);
}
而Redis的configure函数中有进行相关判断
protected function configure(Connection $connection, $name)
{
$connection->setName($name);
if ($this->events && $this->app->bound('events')) {
$connection->setEventDispatcher($this->app->make('events'));
}
return $connection;
}
但是Redis的$events属性默认为false,导致Reids执行命令时无法监听对应事件,解决思路就是修改Redis的这个$events属性了:
$this->app['redis']->enableEvents();
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: