Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NOAUTH Authentication required. Laravel + Redis

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.

like image 730
Mrunal Dadhi Avatar asked Feb 27 '17 10:02

Mrunal Dadhi


1 Answers

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
like image 74
Mrunal Dadhi Avatar answered Oct 16 '22 15:10

Mrunal Dadhi