2017-02-27 211 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