Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure native redis clustering results in error message #45566

Closed
some0ne2 opened this issue Jan 9, 2023 · 11 comments
Closed

configure native redis clustering results in error message #45566

some0ne2 opened this issue Jan 9, 2023 · 11 comments

Comments

@some0ne2
Copy link

some0ne2 commented Jan 9, 2023

  • Laravel Version: 9.44.0
  • PHP Version: 8.1.12
  • Database Driver & Version: phpredis (5.3.7 installed by pecl)

Description: configure native redis clustering results in error message

Steps To Reproduce:

  1. fresh laravel 9 installation
  2. Make sure to config database.php like this:

` 'redis' => [

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

    'options' => [
        'cluster' => env('REDIS_CLUSTER', 'redis'),
    ],

    'clusters' => [
        'default' => [
            'url' => env('REDIS_URL'),
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'username' => env('REDIS_USERNAME'),
            'password' => env('REDIS_PASSWORD'),
            'port' => env('REDIS_PORT', '6379'),
            'database' => env('REDIS_DB', '0'),
        ],

        'cache' => [
            'url' => env('REDIS_URL'),
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'username' => env('REDIS_USERNAME'),
            'password' => env('REDIS_PASSWORD'),
            'port' => env('REDIS_PORT', '6379'),
            'database' => env('REDIS_CACHE_DB', '0'),
        ],
        'session' => [
            'url' => env('REDIS_URL'),
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'username' => env('REDIS_USERNAME'),
            'password' => env('REDIS_PASSWORD'),
            'port' => env('REDIS_PORT', '6379'),
            'database' => env('REDIS_CACHE_DB', '0'),
            'prefix'    => 's:'
        ],

    ],
],`
  1. Env values (only relevant, skipped queue details f.e.):

    • REDIS_HOST=redis-node-5
    • SESSION_DRIVER=redis
    • SESSION_CONNECTION=session
  2. Run redis cluster (docker-compose.yaml)

I'm revceiving the following error message when trying to call default laravel mainpage

array_key_exists(): Argument #2 ($array) must be of type array, null given

Same goes for queue worker (on startup), including more readable details:

root@36f9e34e9915:/var/www/html# php artisan queue:Work INFO Processing jobs from the [{default}] queue. [2023-01-09 10:18:34] local.ERROR: array_key_exists(): Argument #2 ($array) must be of type array, null given {"exception":"[object] (TypeError(code: 0): array_key_exists(): Argument #2 ($array) must be of type array, null given at /var/www/html/vendor/laravel/framework/src/Illuminate/Collections/Arr.php:177) [stacktrace] #0 /var/www/html/vendor/laravel/framework/src/Illuminate/Collections/Arr.php(177): array_key_exists('url', NULL) #1 /var/www/html/vendor/laravel/framework/src/Illuminate/Collections/Arr.php(275): Illuminate\\Support\\Arr::exists(NULL, 'url') #2 /var/www/html/vendor/laravel/framework/src/Illuminate/Collections/Arr.php(599): Illuminate\\Support\\Arr::forget(NULL, Array) #3 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/ConfigurationUrlParser.php(36): Illuminate\\Support\\Arr::pull(NULL, 'url') #4 /var/www/html/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php(186): Illuminate\\Support\\ConfigurationUrlParser->parseConfiguration(NULL) #5 /var/www/html/vendor/laravel/framework/src/Illuminate/Redis/RedisManager.php(133): Illuminate\\Redis\\RedisManager->parseConnectionConfiguration(NULL) #6 [internal function]: Illuminate\\Redis\\RedisManager->Illuminate\\Redis\\{closure}(NULL) [...redacted] "} TypeError array_key_exists(): Argument #2 ($array) must be of type array, null given at vendor/laravel/framework/src/Illuminate/Collections/Arr.php:177

Steps to

Please let me know if more information is required.
-Thanks for help and all of the work on laravel.

@github-actions
Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@driesvints
Copy link
Member

It seems this config is incorrect. Please read the docs here thoroughly: https://laravel.com/docs/9.x/redis#clusters

@some0ne2
Copy link
Author

some0ne2 commented Jan 19, 2023

@dries I use native Redis clustering as taylor mentioned:

If you would like to use native Redis clustering instead of client-side sharding, you may specify this by setting the options.cluster configuration value to redis within your application's config/database.php configuration file:

My config file is excactly as mentioned on laravel page (second code box):

'redis' => [

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

    'options' => [
        'cluster' => env('REDIS_CLUSTER', 'redis'),
    ],

    'clusters' => [
        // ...
    ],

],

My config file seems to be correct.

@tillkruss
Copy link
Contributor

You’re setting HOST and CLUSTER, I think you need to only set one.

@some0ne2
Copy link
Author

@tillkruss I've removed the url from inside theclusters array, error still remains the same.
Config at the moment:

    "clusters" => [

        'default' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'username' => env('REDIS_USERNAME'),
            'password' => env('REDIS_PASSWORD'),
            'port' => env('REDIS_PORT', '6379'),
            'database' => env('REDIS_DB', '0'),
        ],

        'cache' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'username' => env('REDIS_USERNAME'),
            'password' => env('REDIS_PASSWORD'),
            'port' => env('REDIS_PORT', '6379'),
            'database' => env('REDIS_CACHE_DB', '1'),
        ],

        'session' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'username' => env('REDIS_USERNAME'),
            'password' => env('REDIS_PASSWORD'),
            'port' => env('REDIS_PORT', '6379'),
            'database' => env('REDIS_DB', '0'),
            'prefix'   => 's:',
        ],

    ],

Inside laravel doc it says:

'clusters' => [
    // ...
],

so where / how to define the clusters when native Redis clustering is being used?

@tillkruss
Copy link
Contributor

tillkruss commented Jan 19, 2023

You're still using host + port in that config. If you define those then cluster won't be used.

@some0ne2
Copy link
Author

But removing both (host and port), how to tell laravel the hostname of each cluster / port?

@tillkruss
Copy link
Contributor

You run several clusters? That sounds like a terrible idea.

But removing both (host and port), how to tell laravel the hostname of each cluster / port?

Clusters don't use host+port, but an array of primary cluster nodes. Look at RedisManager to see how cluster connections are established.

@some0ne2
Copy link
Author

@tillkruss it seems like the combination of host + port is still "supported"?
Take a look into this.

But I don't see any chance to get it working like this.
I don't run several clusters, I just want to define multiple "connections" of the cluster inside the database.php, so I can setup a different prefix f.e. for sessions / queues running all on the same cluster (since databases are not supported inside redis cluster).

@tillkruss
Copy link
Contributor

You can find your answer on Google/SO.

@ljubadr
Copy link

ljubadr commented May 11, 2023

Check redis cluster docs

Each cluster is array of arrays and not just array

Example from the docs

    'clusters' => [
        'default' => [
            [
                'url' => ...,
                ...
            ],
        ],
    ],

And your example

    'clusters' => [
        'default' => [
            'url' => ...,
            ...
        ],
    ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants