NOAUTH 需要身份验证。 Laravel + Redis

NOAUTH Authentication required. Laravel + Redis

我遇到错误 需要 NOAUTH 身份验证。 我的laravel版本是5.3,我用的是predis 1.1.1连接redis

在 etc/redis/redis.conf 我有:

bind 127.0.0.1
requirepass somepassword

在 .env 文件中我有

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=somepassword
REDIS_PORT=6379

在 config/database.php 我有:

'redis' => [

        'cluster' => false,

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

我正在通过以下方式连接 Redis:

self::$_db = \Redis::connection('default');

并像这样使用它:

self::$_db->pipeline(function ($pipe) use ($profile, $time,$type, $id) {
            $pipe->zadd(self::getProfileKey($profile, $type), $time, $id);
            $pipe->zadd(self::getProfileKey($profile), $time, $type . ':' . $id);
            $pipe->zadd(self::getModelKey($type,$id) . '::favoritedBy', $time, $profile->profile_id);
        });

因此,当我注释掉 requirepass 并将密码作为 null 发送时,它有效但不起作用并在密码到位时抛出错误 NOAUTH Authentication required.。根据我的项目要求,我需要设置密码。请帮忙。提前致谢。

经过一番研究,我找到了解决这个问题的方法:

我们需要添加:

'options' => [
                'parameters' => ['password' => env('REDIS_PASSWORD', null)],
            ],

config数组中。请参阅下面的完整示例:database.php

'redis' => [

        'cluster' => false,

        'default' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 3,
        ],
        'options' => [
            'parameters' => ['password' => env('REDIS_PASSWORD', null)],
        ],
    ],

在 .env 文件中:

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=mmdgreat
REDIS_PORT=6379

我把predis降级解决了! :D

composer require predis/predis:0.8.4

我也在用 Laravel 5.3! :)