NOAUTH Authentication required. Laravel + Redis
Asked Answered
S

3

14

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.

Saxophone answered 27/2, 2017 at 10:9 Comment(0)
S
19

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
Saxophone answered 1/3, 2017 at 13:0 Comment(1)
For what it's worth, on Laravel 6.0.3 with PhpRedis (the PECL extension) and redis-cli 3.0.6, this isn't necessary; it would be ideal to mention which Redis server version you're using. Maybe this additional configuration is a result of using Predis and an older version of Redis.Footed
E
0

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.

Erfert answered 22/3 at 12:53 Comment(0)
T
-3

I solve it downgrading the predis! :D

composer require predis/predis:0.8.4

I'm using the Laravel 5.3 too! :)

Taite answered 7/11, 2018 at 1:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.