Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Yii Framework 2 redis extension Change Log
- Bug #182: Better handle `cache/flush-all` command when cache component is using shared database (rob006)
- Enh #195: Use `Instance::ensure()` to initialize `Session::$redis` (rob006)
- Enh #199: Increase frequency of lock tries when `$timeout` is used in `Mutex::acquire()` (rob006)

- Enh #174: Add ability to set up SSL connection (kulavvy)

2.0.11 November 05, 2019
------------------------
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,19 @@ return [
]
];
```

**SSL configuration** example:
```php
return [
//....
'components' => [
'redis' => [
'class' => 'yii\redis\Connection',
'hostname' => 'localhost',
'port' => 6380,
'database' => 0,
'useSSL' => true,
],
],
];
```
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
}
],
"require": {
"yiisoft/yii2": "~2.0.16"
"yiisoft/yii2": "~2.0.16",
"ext-openssl": "*"
},
"require-dev": {
"phpunit/phpunit": "<7",
Expand Down
8 changes: 8 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ class Connection extends Component
* @var float timeout to use for redis socket when reading and writing data. If not set the php default value will be used.
*/
public $dataTimeout;
/**
* @var boolean Send sockets over SSL protocol. Default state is false.
* @since 2.0.12
*/
public $useSSL = false;
/**
* @var integer Bitmask field which may be set to any combination of connection flags passed to [stream_socket_client()](https://www.php.net/manual/en/function.stream-socket-client.php).
* Currently the select of connection flags is limited to `STREAM_CLIENT_CONNECT` (default), `STREAM_CLIENT_ASYNC_CONNECT` and `STREAM_CLIENT_PERSISTENT`.
Expand Down Expand Up @@ -596,6 +601,9 @@ public function open()
if ($this->dataTimeout !== null) {
stream_set_timeout($socket, $timeout = (int) $this->dataTimeout, (int) (($this->dataTimeout - $timeout) * 1000000));
}
if ($this->useSSL) {
stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
}
if ($this->password !== null) {
$this->executeCommand('AUTH', [$this->password]);
}
Expand Down