yiisoft / yii2-redis

Yii 2 Redis extension.
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
452 stars 183 forks source link

Support tls:// connection string #249

Closed tychovbh closed 2 years ago

tychovbh commented 2 years ago

I'm trying to connect my craftcms to a digitalocean redis cluster.

Digitalocean requires a tls:// connection url: tls://kotc-redis-do-user-698729-0.b.db.ondigitalocean.com

But your plugin doesn't support this only tcp:// and unix://.

I verified that my connection is working if I modify the class Connection.php on line 596:

public function getConnectionString()
    {
        return 'tls://' . ($this->redirectConnectionString ?: "$this->hostname:$this->port");
    }

And my connection worked directly, when I use the tcp:// it returns the following error:

{
    "name": "Redis Socket Exception",
    "message": "Failed to read from socket.\nRedis command was: GET CraftCMS8e0694a5966c89b99615fb42a4a74296",
}

It would be handy to be able to configure de connection scheme mode:

'redis' => [
  'class' => yii\redis\Connection::class,
  'hostname' => getenv('REDIS_HOST'),
  'scheme' => 'tls',
]

My Laravel application already supports the tls:// mode, as you can read here: https://aregsar.com/blog/2020/connecting-laravel-to-digitalocean-managed-redis-cluster/

What steps will reproduce the problem?

  1. Install craft
  2. Install yiisoft/yii2-redis
  3. Create a Digitalocean managed Redis database
  4. Use the connection details in the craft config/app.php
  5. run your application and open it in the browser

What's expected?

To be able to connect caching with a Digitalocean managed Redis database

What do you get instead?

An error:

{
    "name": "Redis Socket Exception",
    "message": "Failed to read from socket.\nRedis command was: GET CraftCMS8e0694a5966c89b99615fb42a4a74296",
}

Additional info

Q A
Yii vesion 2.0
PHP version 8.1
Operating system mac/ubuntu
samdark commented 2 years ago

Do you have some time for a pull request?

tychovbh commented 2 years ago

Sure, ill give it a try!

jamesmacwhite commented 1 year ago

Craft CMS user here. Any rough idea of when the 2.0.18 release might happen. We are looking at enabling TLS on our Redis nodes, but would need to hold until the scheme can be provided via config, as currently we can't override it easily.

The Craft CMS way is specifying the redis configuration in an config/app.php file.

Potentially, I could do a composer alias with as for the Yii redis dependency with this commit, but just for general info for when the official release might happen.

samdark commented 1 year ago

Soon. Want to do it after Yii2 release. There are 4 issues left to solve.

jamesmacwhite commented 1 year ago

@samdark Thanks, I was able to update composer like this for now, to test Redis with TLS

"yiisoft/yii2-redis": "dev-master as 2.0.17"