diff --git a/CHANGELOG.md b/CHANGELOG.md index a101b18e5..1b6525775 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Yii Framework 2 redis extension Change Log ------------------------ - Bug #247: `Cache::getValue()` now returns `false` in case of missing key (rhertogh) +- Enh #249 Added support to set the redis scheme to tls. Add to configuration: `'scheme' => 'tls'` (tychovbh) 2.0.17 January 11, 2022 diff --git a/README.md b/README.md index 1137a8aff..9d4a26fdb 100644 --- a/README.md +++ b/README.md @@ -85,3 +85,18 @@ return [ ], ]; ``` + +**Configuring The Connection Scheme** + +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: +```php +return [ + //.... + 'components' => [ + 'redis' => [ + //.... + 'scheme' => 'tls' + ] + ] +]; +``` diff --git a/composer.json b/composer.json index a90d7ea1a..ca9ff130b 100644 --- a/composer.json +++ b/composer.json @@ -41,5 +41,10 @@ "type": "composer", "url": "https://asset-packagist.org" } - ] + ], + "config": { + "allow-plugins": { + "yiisoft/yii2-composer": true + } + } } diff --git a/src/Connection.php b/src/Connection.php index 41cda898b..c2699cbd6 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -259,6 +259,11 @@ class Connection extends Component * If [[unixSocket]] is specified, hostname and [[port]] will be ignored. */ public $hostname = 'localhost'; + /** + * @var string the connection scheme used for connecting to the redis server. Defaults to 'tcp'. + * @since 2.0.18 + */ + public $scheme = 'tcp'; /** * @var string if the query gets redirected, use this as the temporary new hostname * @since 2.0.11 @@ -593,7 +598,7 @@ public function getConnectionString() return 'unix://' . $this->unixSocket; } - return 'tcp://' . ($this->redirectConnectionString ?: "$this->hostname:$this->port"); + return $this->scheme . '://' . ($this->redirectConnectionString ?: "$this->hostname:$this->port"); } /**