Skip to content

[7.x] Add support for PhpRedis 5.3 options parameter - #33799

Merged
taylorotwell merged 2 commits into
laravel:7.xfrom
tillkruss:patch-1
Aug 11, 2020
Merged

taylorotwell merged 2 commits into
laravel:7.xfrom
tillkruss:patch-1

Conversation

@tillkruss

@tillkruss tillkruss commented Aug 9, 2020 •

Copy link
Copy Markdown
Contributor

PhpRedis added a 7th parameter to support stream context options and Redis 6 authentication. This is particularly useful when a certificate is required to connect to Redis, or certificate verification needs to be disabled.

$redis = new Redis;

$redis->connect('127.0.0.1', 6379, 1, null, 0, 0, [
    'auth' => ['username', 'secret'],
    'stream' => [
        'verify_peer' => false,
    ],
]);

The database config would look like this (context should really be called options, but we already use that):

return [

    'redis' => [

        'client' => env('REDIS_CLIENT', 'phpredis'),

        'options' => [
            'cluster' => env('REDIS_CLUSTER', 'phpredis'),
            'prefix' => env('REDIS_PREFIX'),
        ],

        'default' => [
            'host' => 'tls://127.0.0.1',
            'password' => 'secret',
            'port' => 6379,
            'database' => 0,

            // new:
            'context' => [
                'auth' => ['username', 'secret'],
                'stream' => [
                    'verify_peer' => false,
                ],
            ]
        ],

    ],

];

For cluster connections, the context would be pulled from redis.options.context.

@tillkruss
tillkruss marked this pull request as ready for review August 9, 2020 19:33
@tillkruss tillkruss changed the title Add support for PhpRedis 5.3 options parameter [7.x] Add support for PhpRedis 5.3 options parameter Aug 9, 2020
Comment thread src/Illuminate/Redis/Connectors/PhpRedisConnector.php
@taylorotwell
taylorotwell merged commit 76b175d into laravel:7.x Aug 11, 2020
salmanarshad321 pushed a commit to salmanarshad321/framework that referenced this pull request Sep 23, 2026
* fix indentation

* add `context` support for PhpRedis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants