-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[8.x] Make it possible to use prefixes on Predis per Connection #40083
Conversation
@@ -42,6 +42,10 @@ public function connectToCluster(array $config, array $clusterOptions, array $op | |||
{ | |||
$clusterSpecificOptions = Arr::pull($config, 'options', []); | |||
|
|||
if (! empty($config['prefix'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty is not the right function here. it will not permit using 0 as a prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simply copied the code from
if (! empty($config['prefix'])) { |
Do we want to allow zeros within PHPRedis Connector as well?
To allow the use of zero. Change the function from empty to isset
Please share what the actual formatted Redis configuration would look like using these new options. Please mark as ready for review when you have done so. |
Assuming I'm understanding your question correct. The formatted Redis configuration would look like: /config/database.php
|
We were just looking into this and noticed it was already possible to put a prefix on a specific store. You just had to nest it under an 'redis' => [
'cache' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 1),
'options' => [ // 👈 you needed this
'prefix' => env('REDIS_PREFIX', 'prefix2:'),
]
],
], So now this PR introduces an inconsistency. You can now add un-nested Although my first instinct was to plop |
It's been a while since I've look at the code but the change was centered around how predis client code expected the prefix to be presented. Atleast when I committed the code there was no way to pass this information to the predis code in a way that would allow it to function. It's possible that code changes now allow for it. |
In the few lines above what was added in this PR, you can see that the $formattedOptions = array_merge(
['timeout' => 10.0], $options, Arr::pull($config, 'options', [])
); |
framework/src/Illuminate/Redis/RedisManager.php Lines 107 to 115 in 4a2f5e9
If you take a look at the code above. That's the parent code that calls the function that I modified. As you can see originally it would only send the global redis options not the individual options through the $config variable. This behaviour has since changed which is why it now works for you. But I did want to point out that this code does seem pointless now but it does actually keep the setting the same between the two redis drivers settings. As you can setup a prefix in the exact same way for phpredis. framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php Lines 98 to 100 in 2f51de5
|
The first argument passed into |
@jasonvarga Okay, I just checked on my local machine and you were correct. Yeah, that's really is my bad. :( I swear down that options didn't work for me when I wrote this fix. |
This PR allows the ability to use prefixes on a per connection basis for Predis.
Basically the only way to setup a prefix is by doing the following
['redis' => ['options' => ['prefix' => 'prefix:']]]
in the/config/database.php
file.So copying a similar setup in PHPRedis. Each connection can be given a unique prefix by defining them within the individual connection config like so
['redis' => ['connection1' => ['prefix' => 'prefix:'], 'connection2' => ['prefix' => 'prefix2:']]]
.