File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010 'type ' => 'redis ' ,
1111 // 服务器地址
1212 'host ' => '127.0.0.1 ' ,
13+ // 无 ACL 用户请留空 username(Redis 6.0 起支持用户名 + 密码认证)
14+ 'username ' => '' ,
15+ // redis密码
16+ 'password ' => '' ,
1317 // 缓存前缀
1418 'prefix ' => 'cache: ' ,
1519 // 默认缓存有效期 0表示永久缓存
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ class Redis extends Driver
3232 protected $ options = [
3333 'host ' => '127.0.0.1 ' ,
3434 'port ' => 6379 ,
35+ 'username ' => '' ,
3536 'password ' => '' ,
3637 'select ' => 0 ,
3738 'timeout ' => 0 ,
@@ -58,7 +59,11 @@ public function __construct(array $options = [])
5859 $ this ->handler = new \Redis ;
5960 $ this ->handler ->connect ($ this ->options ['host ' ], (int ) $ this ->options ['port ' ], (int ) $ this ->options ['timeout ' ]);
6061 if ('' != $ this ->options ['password ' ]) {
61- $ this ->handler ->auth ($ this ->options ['password ' ]);
62+ if ('' != $ this ->options ['username ' ]) {
63+ $ this ->handler ->auth ([$ this ->options ['username ' ], $ this ->options ['password ' ]]);
64+ } else {
65+ $ this ->handler ->auth ($ this ->options ['password ' ]);
66+ }
6267 }
6368 } elseif (class_exists ('\Predis\Client ' )) {
6469 $ params = [];
@@ -71,6 +76,9 @@ public function __construct(array $options = [])
7176 if ('' == $ this ->options ['password ' ]) {
7277 unset($ this ->options ['password ' ]);
7378 }
79+ if ('' == $ this ->options ['username ' ]) {
80+ unset($ this ->options ['username ' ]);
81+ }
7482 $ this ->handler = new \Predis \Client ($ this ->options , $ params );
7583 $ this ->options ['prefix ' ] = '' ;
7684 } else {
You can’t perform that action at this time.
0 commit comments