Mrunal Dadhi
Mrunal Dadhi

Reputation: 430

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.

Upvotes: 14

Views: 30263

Answers (3)

Nuryagdy Mustapayev
Nuryagdy Mustapayev

Reputation: 775

I got same error in Symfony, specifically symfony/cache. Problem was that REDIS_DSN environment variable did not contain password information, but redis docker container required the password. So changing this:

REDIS_DSN=redis://<redis-host-name>:6379

to this

REDIS_DSN=redis://<redis-password>@<redis-host-name>:6379

Symfony cache config:

framework:
    cache:
        default_redis_provider: '%env(REDIS_DSN)%'
        pools:
            my_cache_pool:
                adapter: cache.adapter.redis

In PHP you can also check the credentials this way:

    $redis = new \Redis([
        'host' => 'redis-host-name',
        'port' => 6379,
        'auth' => 'redis-password',
    ]);

Note: I did not find symfony specific question in stack overflow, so decided to add answer here.

Upvotes: 1

Luiz Felipe F M Costa
Luiz Felipe F M Costa

Reputation: 100

I solve it downgrading the predis! :D

composer require predis/predis:0.8.4

I'm using the Laravel 5.3 too! :)

Upvotes: -3

Mrunal Dadhi
Mrunal Dadhi

Reputation: 430

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

Upvotes: 19

Related Questions