2017-02-27 207 views
0

我得到错误NOAUTH认证要求。 我的laravel版本是5.3,我使用predis 1.1.1来连接redis。NOAUTH需要身份验证。 Laravel + Redis

在等/ redis的/ redis.conf

我:

bind 127.0.0.1 
requirepass somepassword 
在.ENV文件

REDIS_HOST=127.0.0.1 
REDIS_PASSWORD=somepassword 
REDIS_PORT=6379 
在配置

/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和发送密码为空它的工作原理,但它不工作,当密码到位抛出错误NOAUTH Authentication required.。我需要根据我的项目要求设置密码。请帮忙。提前致谢。

回答

1

因此,一些研究之后,我得到了针对此问题的解决方案:

我们需要添加:

'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