NOAUTH需要身份验证。 Laravel + Redis

时间:2017-02-27 10:09:35

标签: redis laravel-5.3 predis

我收到错误需要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.。我需要根据我的项目要求设置密码。请帮忙。提前谢谢。

2 个答案:

答案 0 :(得分:9)

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

我们需要添加:

'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

答案 1 :(得分:0)

我解决了该问题,从而降低了predis的性能! :D

composer require predis/predis:0.8.4

我也在使用Laravel 5.3! :)

相关问题