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

[8.x] Improve PhpRedis flushing #40544

Merged
merged 6 commits into from
Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/Illuminate/Redis/Connections/PhpRedisClusterConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,21 @@

class PhpRedisClusterConnection extends PhpRedisConnection
{
//
/**
* Flush the selected Redis database on all master nodes.
*
* @return mixed
*/
public function flushdb()
{
$arguments = func_get_args();

$async = strtoupper((string) $arguments[0] ?? null) === 'ASYNC';

foreach ($this->client->_masters() as $master) {
$async
? $this->command('rawCommand', [$master, 'flushdb', 'async'])
: $this->command('flushdb', [$master]);
}
}
}
13 changes: 6 additions & 7 deletions src/Illuminate/Redis/Connections/PhpRedisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Redis;
use RedisCluster;
use RedisException;

/**
Expand Down Expand Up @@ -495,17 +494,17 @@ public function createSubscription($channels, Closure $callback, $method = 'subs
/**
* Flush the selected Redis database.
*
* @return void
* @return mixed
*/
public function flushdb()
{
if (! $this->client instanceof RedisCluster) {
return $this->command('flushdb');
}
$arguments = func_get_args();

foreach ($this->client->_masters() as $master) {
$this->client->flushDb($master);
if (strtoupper((string) $arguments[0] ?? null) === 'ASYNC') {
Copy link
Contributor

@TheLevti TheLevti Jan 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes a lot of tests to fail for me with an index access that does not exist.

It should be if (strtoupper((string) ($arguments[0] ?? null)) === 'ASYNC') {

Copy link
Contributor

@TheLevti TheLevti Jan 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As sometimes there are no arguments at all and the string cast takes precedence.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make a PR with tests and the changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #40571

return $this->command('flushdb', [true]);
}

return $this->command('flushdb');
}

/**
Expand Down