RedisClusterProxy.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Cache\Traits;
  11. /**
  12. * @author Alessandro Chitolina <alekitto@gmail.com>
  13. *
  14. * @internal
  15. */
  16. class RedisClusterProxy
  17. {
  18. private $redis;
  19. private $initializer;
  20. public function __construct(\Closure $initializer)
  21. {
  22. $this->initializer = $initializer;
  23. }
  24. public function __call(string $method, array $args)
  25. {
  26. $this->redis ?: $this->redis = $this->initializer->__invoke();
  27. return $this->redis->{$method}(...$args);
  28. }
  29. public function hscan($strKey, &$iIterator, $strPattern = null, $iCount = null)
  30. {
  31. $this->redis ?: $this->redis = $this->initializer->__invoke();
  32. return $this->redis->hscan($strKey, $iIterator, $strPattern, $iCount);
  33. }
  34. public function scan(&$iIterator, $strPattern = null, $iCount = null)
  35. {
  36. $this->redis ?: $this->redis = $this->initializer->__invoke();
  37. return $this->redis->scan($iIterator, $strPattern, $iCount);
  38. }
  39. public function sscan($strKey, &$iIterator, $strPattern = null, $iCount = null)
  40. {
  41. $this->redis ?: $this->redis = $this->initializer->__invoke();
  42. return $this->redis->sscan($strKey, $iIterator, $strPattern, $iCount);
  43. }
  44. public function zscan($strKey, &$iIterator, $strPattern = null, $iCount = null)
  45. {
  46. $this->redis ?: $this->redis = $this->initializer->__invoke();
  47. return $this->redis->zscan($strKey, $iIterator, $strPattern, $iCount);
  48. }
  49. }