NOAUTH Authentication required. Laravel + Redis

孤街醉人 提交于 2019-12-06 03:49:41

问题


I am getting error NOAUTH Authentication required. My laravel version is 5.3 and I am using predis 1.1.1 to connect redis.

in etc/redis/redis.conf I have:

bind 127.0.0.1
requirepass somepassword

in .env file I have

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=somepassword
REDIS_PORT=6379

in config/database.php I have:

'redis' => [

        'cluster' => false,

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

I am connecting redis via:

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

and using it like:

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);
        });

So, when I comment out requirepass and send password as null it works but it does not work and throw error NOAUTH Authentication required. when the password is in place. I need to have password in place as per my project requirement. Please help. Thanks in advance.


回答1:


So after some research, I got a solution for this issue:

We need to add:

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

In config array. See complete example below: 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)],
        ],
    ],

In .env file:

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=mmdgreat
REDIS_PORT=6379



回答2:


I solve it downgrading the predis! :D

composer require predis/predis:0.8.4

I'm using the Laravel 5.3 too! :)



来源:https://stackoverflow.com/questions/42482945/noauth-authentication-required-laravel-redis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!