NOAUTH需要身份验证.Laravel + Redis

Mru*_*dhi 5 redis predis laravel-5.3

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

在etc/redis/redis.conf我有:

bind 127.0.0.1
requirepass somepassword
Run Code Online (Sandbox Code Playgroud)

在.env文件中我有

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=somepassword
REDIS_PORT=6379
Run Code Online (Sandbox Code Playgroud)

在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,
        ],
Run Code Online (Sandbox Code Playgroud)

我通过以下方式连接redis:

self::$_db = \Redis::connection('default');
Run Code Online (Sandbox Code Playgroud)

并使用它像:

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);
        });
Run Code Online (Sandbox Code Playgroud)

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

Mru*_*dhi 9

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

我们需要添加:

'options' => [
                'parameters' => ['password' => env('REDIS_PASSWORD', null)],
            ],
Run Code Online (Sandbox Code Playgroud)

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)],
        ],
    ],
Run Code Online (Sandbox Code Playgroud)

在.env文件中:

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=mmdgreat
REDIS_PORT=6379
Run Code Online (Sandbox Code Playgroud)