Skip to content

Commit 0d6fb05

Browse files
kulavvypmoscicki
authored andcommitted
add use ssl
1 parent c324e57 commit 0d6fb05

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,19 @@ return [
6262
]
6363
];
6464
```
65+
66+
**SSL configuration** example:
67+
```php
68+
return [
69+
//....
70+
'components' => [
71+
'redis' => [
72+
'class' => 'yii\redis\Connection',
73+
'hostname' => 'localhost',
74+
'port' => 6380,
75+
'database' => 0,
76+
'useSSL' => true,
77+
],
78+
],
79+
];
80+
```

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
}
1919
],
2020
"require": {
21-
"yiisoft/yii2": "~2.0.16"
21+
"yiisoft/yii2": "~2.0.16",
22+
"ext-openssl": "*"
2223
},
2324
"require-dev": {
2425
"phpunit/phpunit": "<7",

src/Connection.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ class Connection extends Component
281281
* @var float timeout to use for redis socket when reading and writing data. If not set the php default value will be used.
282282
*/
283283
public $dataTimeout;
284+
/**
285+
* @var boolean Send sockets over SSL protocol. Default state is false.
286+
* @since 2.0.12
287+
*/
288+
public $useSSL = false;
284289
/**
285290
* @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).
286291
* Currently the select of connection flags is limited to `STREAM_CLIENT_CONNECT` (default), `STREAM_CLIENT_ASYNC_CONNECT` and `STREAM_CLIENT_PERSISTENT`.
@@ -596,6 +601,9 @@ public function open()
596601
if ($this->dataTimeout !== null) {
597602
stream_set_timeout($socket, $timeout = (int) $this->dataTimeout, (int) (($this->dataTimeout - $timeout) * 1000000));
598603
}
604+
if ($this->useSSL) {
605+
stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
606+
}
599607
if ($this->password !== null) {
600608
$this->executeCommand('AUTH', [$this->password]);
601609
}

0 commit comments

Comments
 (0)