Skip to content

Commit 3790ebf

Browse files
samdarkrvkulikovBizley
authored
Fix #223: Add Connection::$username for using username for authentication
Co-authored-by: Roman Kulikov <r.v.kulikov@yandex.ru> Co-authored-by: Bizley <pawel@positive.codes>
1 parent c65d41d commit 3790ebf

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Yii Framework 2 redis extension Change Log
44
2.0.16 under development
55
------------------------
66

7-
- no changes in this release.
7+
- Enh #223: Add `Connection::$username` for using username for authentication (samdark, rvkulikov)
88

99

1010
2.0.15 May 05, 2021

src/Connection.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ class Connection extends Component
276276
* @since 2.0.1
277277
*/
278278
public $unixSocket;
279+
/**
280+
* @var string|null username for establishing DB connection. Defaults to `null` meaning AUTH command will be performed without username.
281+
* Username was introduced in Redis 6.
282+
* @link https://redis.io/commands/auth
283+
* @link https://redis.io/topics/acl
284+
* @since 2.0.16
285+
*/
286+
public $username;
279287
/**
280288
* @var string the password for establishing DB connection. Defaults to null meaning no AUTH command is sent.
281289
* See https://redis.io/commands/auth
@@ -638,7 +646,7 @@ public function open()
638646
stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
639647
}
640648
if ($this->password !== null) {
641-
$this->executeCommand('AUTH', [$this->password]);
649+
$this->executeCommand('AUTH', array_filter([$this->username, $this->password]));
642650
}
643651
if ($this->database !== null) {
644652
$this->executeCommand('SELECT', [$this->database]);

0 commit comments

Comments
 (0)