我已经在Homestead中设置了Laravel的全新安装,并且按照Laravel docs https://laravel.com/docs/7.x/redis#phpredis的建议安装了PhpRedis。
我按照本指南安装了PhpRedis https://webstoked.com/install-phpredis-laravel-ubuntu/
在Laravel文档和我链接的有关安装PhpRedis的指南中,都要求我在config / app.php中重命名Redis别名。
If you plan to use PhpRedis extension along with the Redis Facade alias, you should rename it to something else, like RedisManager, to avoid a collision with the Redis class. You can do that in the aliases section of your app.php config file.
- Laravel Docs
为了进一步加深我的困惑,Laravel文档接着说您应该完全删除别名。
To avoid class naming collisions with the Redis PHP extension itself, you will need to delete or rename the Illuminate\Support\Facades\Redis facade alias from your app configuration file's aliases array. Generally, you should remove this alias entirely and only reference the facade by its fully qualified class name while using the Redis PHP extension.
- Laravel Docs
我的主要问题是:
最佳答案
在laravel项目中,有两种不同的配置/方式可以使用redis
。
predis
,它在您的vendor
文件夹中。这是位于here的“适用于PHP和HHVM的灵活且功能完善的Redis客户端”。这是一个用php
编写的软件包/库。 PhpRedis
,它是用C
编写并位于here的扩展。 protected function connector()
{
switch ($this->driver) {
case 'predis':
return new Connectors\PredisConnector;
case 'phpredis':
return new Connectors\PhpRedisConnector;
}
}
In the framework there is a check. While creating the
PhpRedis client
of Redis, it is checking whether thenew Redis
instance is Facade because PhpRedis is also usingRedis
name is you can see from here. So if you want to use PhpRedis in your laravel framework you better rename your facade because it will cause collision.
If you are going to use
predis
as client, then you can leave it as-is. If you are going to usePhpRedis
as client, then you need to rename alias.
You will use
RedisManager::someMethod()
if you choose PhpRedis. You will useRedis::someMethod()
if you use predis.
关于laravel - 在Laravel 7中配置PhpRedis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62452765/