Skip to content

Conversation

@alexmontoanelli
Copy link
Contributor

Hi,

PhpRedisConnector try to set 4 options (max_retries,backoff_algorithm,backoff_base,backoff_cap) before
the connection has been established, and so, the options has no effect at all.

With a single line move, creating the connection/client before, the options then is set successfully on client.

@alexmontoanelli alexmontoanelli changed the title Establish connection first, before set the options [12.x] - Redis - Establish connection first, before set the options Apr 11, 2025
@taylorotwell
Copy link
Member

Don't these values specifically control the amount of retries when connecting though?

@alexmontoanelli
Copy link
Contributor Author

These values are passed to client, in this case \Redis, to controll retries and backoff strategies.

Screenshot 2025-04-11 at 11 08 00

If you set in your database.conf this settings (max_retries, backoff_algorithm), and then run
this code, you get the default values.

` php
$connection = Redis::connection();
$option1 = $connection->client()->getOption(\Redis::OPT_MAX_RETRIES);
$option2 = $connection->client()->getOption(\Redis::OPT_BACKOFF_ALGORITHM);
dump($option1, $option2);

`

//database settings
Screenshot 2025-04-11 at 11 10 21

//code to get driver settings
Screenshot 2025-04-11 at 11 10 46

//return values, before and after the fix
//10,0 (default options for max retries, and backoff), event (with database configure)
//30, 2 (respecting the config file)
Screenshot 2025-04-11 at 11 11 27

@taylorotwell taylorotwell merged commit 64fb35b into laravel:12.x Apr 11, 2025
117 checks passed
@PavelKhatsimtsau
Copy link

Don't these values specifically control the amount of retries when connecting though?

Hey. Thanks everyone for the provided fix. We have faced with the same type of problem.
I would like to comment out a little bit regarding actual reason causing described above behavior - hopefully it might be useful in the future.
Previous version of the PhpRedisConnector will work fine in terms of any versions of phpredis extension equal or above 6.0 - as starting from that particular version documentation link - it is possible to use connection related parameters (including controls ones - as retry_interval, max_retry_limit and so on) in the Redis client constructor directly - eventually specified configuration parameters will be lazily applied.

Any version below 6.0 requires to establish preliminary connection to the redis server - and once it is connected successfully - we can send configuration commands to alter its behavior.

Thanks!

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