Skip to content

Wrong parameters order for array_merge inside PhpRedisConnector::connect #36986

Closed
@slia-stryber

Description

@slia-stryber

return $this->createClient(array_merge(
$config, $options, Arr::pull($config, 'options', [])
));

Inside config/database.php I have such configuration:

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

    'options' => [
        'cluster' => env('REDIS_CLUSTER', false),
        'prefix' => env(
            'REDIS_PREFIX',
            Str::slug(env('APP_NAME', 'laravel'), '_') . '_database_'
        ),
    ],

    //...

    'dev_consumer' => [
        'url' => env('REDIS_DEV_CONSUMER_URL'),
        'host' => env('REDIS_DEV_CONSUMER_HOST', '127.0.0.1'),
        'password' => env('REDIS_DEV_CONSUMER_PASSWORD', null),
        'port' => env('REDIS_DEV_CONSUMER_PORT', '6379'),
        'database' => env('REDIS_DEV_CONSUMER_DB', '0'),
        'timeout' => 15,
        'persistent' => 0,
        'prefix' => 'other_name_database_',
    ]
],

and I expect that the prefix option('other_name_database') from the dev_consumer connection will override the prefix option from the options array.
But it doesn't happen 😢.

If I'm correct method should look like:

public function connect(array $config, array $options)
{
    $connector = function () use ($config, $options) {
        return $this->createClient(array_merge(
            $options, $config, Arr::pull($config, 'options', [])
        ));
    };

    return new PhpRedisConnection($connector(), $connector, $config);
}

but I'm not sure what it might affect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions