This commit is contained in:
Paolo A
2024-08-13 13:44:16 +00:00
parent 1bbb23088d
commit e796d76612
4001 changed files with 30101 additions and 40075 deletions

View File

@@ -4,5 +4,21 @@ namespace Illuminate\Redis\Connections;
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]);
}
}
}

View File

@@ -7,7 +7,6 @@ use Illuminate\Contracts\Redis\Connection as ConnectionContract;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Redis;
use RedisCluster;
use RedisException;
/**
@@ -15,6 +14,8 @@ use RedisException;
*/
class PhpRedisConnection extends Connection implements ConnectionContract
{
use PacksPhpRedisValues;
/**
* The connection creation callback.
*
@@ -71,7 +72,7 @@ class PhpRedisConnection extends Connection implements ConnectionContract
}
/**
* Set the string value in argument as value of the key.
* Set the string value in the argument as the value of the key.
*
* @param string $key
* @param mixed $value
@@ -220,7 +221,7 @@ class PhpRedisConnection extends Connection implements ConnectionContract
$options = [];
foreach (array_slice($dictionary, 0, 3) as $i => $value) {
if (in_array($value, ['nx', 'xx', 'ch', 'incr', 'NX', 'XX', 'CH', 'INCR'], true)) {
if (in_array($value, ['nx', 'xx', 'ch', 'incr', 'gt', 'lt', 'NX', 'XX', 'CH', 'INCR', 'GT', 'LT'], true)) {
$options[] = $value;
unset($dictionary[$i]);
@@ -493,23 +494,17 @@ class PhpRedisConnection extends Connection implements ConnectionContract
/**
* 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();
if (strtoupper((string) ($arguments[0] ?? null)) === 'ASYNC') {
return $this->command('flushdb', [true]);
}
foreach ($this->client->_masters() as [$host, $port]) {
$redis = tap(new Redis)->connect($host, $port);
if (isset($this->config['password']) && ! empty($this->config['password'])) {
$redis->auth($this->config['password']);
}
$redis->flushDb();
}
return $this->command('flushdb');
}
/**
@@ -556,7 +551,7 @@ class PhpRedisConnection extends Connection implements ConnectionContract
}
/**
* Apply prefix to the given key if necessary.
* Apply a prefix to the given key if necessary.
*
* @param string $key
* @return string

View File

@@ -2,7 +2,19 @@
namespace Illuminate\Redis\Connections;
use Predis\Command\ServerFlushDatabase;
class PredisClusterConnection extends PredisConnection
{
//
/**
* Flush the selected Redis database on all cluster nodes.
*
* @return void
*/
public function flushdb()
{
$this->client->executeCommandOnNodes(
tap(new ServerFlushDatabase)->setArguments(func_get_args())
);
}
}

View File

@@ -4,8 +4,6 @@ namespace Illuminate\Redis\Connections;
use Closure;
use Illuminate\Contracts\Redis\Connection as ConnectionContract;
use Predis\Command\ServerFlushDatabase;
use Predis\Connection\Aggregate\ClusterInterface;
/**
* @mixin \Predis\Client
@@ -52,20 +50,4 @@ class PredisConnection extends Connection implements ConnectionContract
unset($loop);
}
/**
* Flush the selected Redis database.
*
* @return void
*/
public function flushdb()
{
if (! $this->client->getConnection() instanceof ClusterInterface) {
return $this->command('flushdb');
}
foreach ($this->getConnection() as $node) {
$node->executeCommand(new ServerFlushDatabase);
}
}
}