php - 在 Laravel 中配置 Redis 时遇到的问题

标签 php laravel redis

我已经借助以下命令在 Laravel 中安装了 predis:

composer require predis/predis

我还在config下配置了database.php为:

'redis' => [

                'client' => 'predis',

                'clusters' => [
                        'default' => [
                                [
                                        'host' => env('REDIS_HOST', '10.21.7.28'),
                                        'password' => env('REDIS_PASSWORD', null),
                                        'port' => env('REDIS_PORT', 6379),
                                        'database' => 0,
                                        'read_write_timeout' => 60,
                                ],
                        ],
                ],

        ],

而且我还在 session.php 文件中将 session 驱动程序定义为 redis:

'driver' => env('SESSION_DRIVER', 'redis'),

尽管进行了所有必需的配置,我还是收到了这个错误:

Redis connection [redis] not configured.

错误的详细信息是:

/home/dixon/php7esupport/esupport/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php

 * @param  string|null  $name
 * @return \Illuminate\Redis\Connections\Connection
 *
 * @throws \InvalidArgumentException
 */

    public function resolve($name = null)
    {
        $name = $name ?: 'default';

        $options = $this->config['options'] ?? [];

        if (isset($this->config[$name])) {
            return $this->connector()->connect($this->config[$name], $options);
        }

        if (isset($this->config['clusters'][$name])) {
            return $this->resolveCluster($name);
        }

        throw new InvalidArgumentException("Redis connection [{$name}] not configured.");
    }

    /**
     * Resolve the given cluster connection by name.
     *
     * @param  string  $name
     * @return \Illuminate\Redis\Connections\Connection
     */
    protected function resolveCluster($name)
    {
        $clusterOptions = $this->config['clusters']['options'] ?? [];

        return $this->connector()->connectToCluster(
            $this->config['clusters'][$name], $clusterOptions, $this->config['options'] ?? []
        );
    }


    /**
     * Get the connector instance for the current driver.
     *
Arguments

    "Redis connection [redis] not configured."

我不知道我到底错过了什么。谁能告诉我我遗漏了哪一部分?

最佳答案

我得到了这个问题的解决方案。我只是在其中添加了以下部分 config/session.php 文件为:

'driver' => env('SESSION_DRIVER', 'redis'),
'connection' => 'default',

关于php - 在 Laravel 中配置 Redis 时遇到的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50323927/

相关文章:

基于 Scala 磁盘的 Map

python - 在 Python 中设置 celery 任务后端的麻烦

php - 迭代每一行并获取计数 php mysql

javascript - Vue JS,如何使 axios 请求 API 在加载 HTML DOM 组件之前首先运行?

php - 使用 Laravel 一次插入多条记录

java - 如何管理 Redisson 嵌套对象的过期

php - MySQL - 新数据库记录需要静态时间戳

php - 如何使用php同时向同一张 table 上的2个人发送电子邮件

php - MySQL查询没有返回任何结果

php - 自动调整 Excel 列宽