Skip to content

Commit f96b872

Browse files
authored
Fix #249 Added support to set the redis scheme to tls. Add to configuration: 'scheme' => 'tls'
1 parent 1443c50 commit f96b872

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Yii Framework 2 redis extension Change Log
55
------------------------
66

77
- Bug #247: `Cache::getValue()` now returns `false` in case of missing key (rhertogh)
8+
- Enh #249 Added support to set the redis scheme to tls. Add to configuration: `'scheme' => 'tls'` (tychovbh)
89

910

1011
2.0.17 January 11, 2022

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,18 @@ return [
8585
],
8686
];
8787
```
88+
89+
**Configuring The Connection Scheme**
90+
91+
By default, Redis will use the tcp scheme when connecting to your Redis server; however, you may use TLS / SSL encryption by specifying a scheme configuration option in your application configuration:
92+
```php
93+
return [
94+
//....
95+
'components' => [
96+
'redis' => [
97+
//....
98+
'scheme' => 'tls'
99+
]
100+
]
101+
];
102+
```

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,10 @@
4141
"type": "composer",
4242
"url": "https://asset-packagist.org"
4343
}
44-
]
44+
],
45+
"config": {
46+
"allow-plugins": {
47+
"yiisoft/yii2-composer": true
48+
}
49+
}
4550
}

src/Connection.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ class Connection extends Component
259259
* If [[unixSocket]] is specified, hostname and [[port]] will be ignored.
260260
*/
261261
public $hostname = 'localhost';
262+
/**
263+
* @var string the connection scheme used for connecting to the redis server. Defaults to 'tcp'.
264+
* @since 2.0.18
265+
*/
266+
public $scheme = 'tcp';
262267
/**
263268
* @var string if the query gets redirected, use this as the temporary new hostname
264269
* @since 2.0.11
@@ -593,7 +598,7 @@ public function getConnectionString()
593598
return 'unix://' . $this->unixSocket;
594599
}
595600

596-
return 'tcp://' . ($this->redirectConnectionString ?: "$this->hostname:$this->port");
601+
return $this->scheme . '://' . ($this->redirectConnectionString ?: "$this->hostname:$this->port");
597602
}
598603

599604
/**

0 commit comments

Comments
 (0)