laravel - 在Laravel 7中配置PhpRedis

标签 laravel redis phpredis laravel-facade

我已经在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



我的主要问题是:
  • “如果您打算将PhpRedis扩展名与Redis Facade别名一起使用”是什么意思?
  • 我何时应该重命名别名,将其删除或保留原样?
  • 取决于我是否重命名或删除别名,这对使用Redis的影响如何?
  • 最佳答案

    在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;
        }
    }
    

  • “如果您打算将PhpRedis扩展名与Redis Facade别名一起使用”是什么意思?

    In the framework there is a check. While creating the PhpRedis client of Redis, it is checking whether the new Redis instance is Facade because PhpRedis is also using Redis 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 use PhpRedis as client, then you need to rename alias.

  • 取决于我是否重命名或删除别名,这对使用Redis的影响如何?

    You will use RedisManager::someMethod() if you choose PhpRedis. You will use Redis::someMethod() if you use predis.

  • 关于laravel - 在Laravel 7中配置PhpRedis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62452765/

    相关文章:

    amazon-web-services - AWS-EC2 Redis-服务器 RDB 快照写入错误

    php redis扩展整数溢出

    javascript - 如何使用get发送数据而不在url中显示参数?

    php - 使用 Laravel Nova 显示指标趋势的问题 - 参数太少

    node.js - Redis 发布/订阅限制

    Redis如何存储关联数组?设置或散列或列表?

    php - 如何在 Travis 上启用 PHP redis 扩展

    php - 每秒只上传一张图片显示 Laravel 中的错误

    php - 调用未定义的函数 Project\Http\Controllers\array_sort()

    node.js - 用 nets 和 nodejs 堆叠字符串