PredisClusterConnection.php 939 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Illuminate\Redis\Connections;
  3. use Predis\Command\Redis\FLUSHDB;
  4. use Predis\Command\ServerFlushDatabase;
  5. class PredisClusterConnection extends PredisConnection
  6. {
  7. /**
  8. * Get the keys that match the given pattern.
  9. *
  10. * @param string $pattern
  11. * @return array
  12. */
  13. public function keys(string $pattern)
  14. {
  15. $keys = [];
  16. foreach ($this->client as $node) {
  17. $keys[] = $node->keys($pattern);
  18. }
  19. return array_merge(...$keys);
  20. }
  21. /**
  22. * Flush the selected Redis database on all cluster nodes.
  23. *
  24. * @return void
  25. */
  26. public function flushdb()
  27. {
  28. $command = class_exists(ServerFlushDatabase::class)
  29. ? ServerFlushDatabase::class
  30. : FLUSHDB::class;
  31. foreach ($this->client as $node) {
  32. $node->executeCommand(tap(new $command)->setArguments(func_get_args()));
  33. }
  34. }
  35. }