【问题标题】:Issue faced during the Redis Configuration in Laravel在 Laravel 中配置 Redis 时遇到的问题
【发布时间】:2018-05-14 06:05:22
【问题描述】:

我已经借助以下命令在 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 文件中将会话驱动定义为 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."

我无法弄清楚我到底错过了什么。谁能告诉我缺少哪一部分?

【问题讨论】:

  • 是托管服务还是服务器?
  • 这是一个托管服务器。
  • Redis 绝对不适用于托管。询问您的托管服务,但据我所知,它不起作用。

标签: php laravel redis


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-10
    • 2020-04-09
    • 2014-04-21
    • 1970-01-01
    • 2022-01-09
    • 2016-04-14
    • 2013-08-13
    • 2016-04-15
    相关资源
    最近更新 更多