RedisProxy.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 Nicolas Grekas <p@tchwork.com>
  13. *
  14. * @internal
  15. */
  16. class RedisProxy
  17. {
  18. private $redis;
  19. private $initializer;
  20. private $ready = false;
  21. public function __construct(\Redis $redis, \Closure $initializer)
  22. {
  23. $this->redis = $redis;
  24. $this->initializer = $initializer;
  25. }
  26. public function __call($method, array $args)
  27. {
  28. $this->ready ?: $this->ready = $this->initializer->__invoke($this->redis);
  29. return $this->redis->{$method}(...$args);
  30. }
  31. public function hscan($strKey, &$iIterator, $strPattern = null, $iCount = null)
  32. {
  33. $this->ready ?: $this->ready = $this->initializer->__invoke($this->redis);
  34. return $this->redis->hscan($strKey, $iIterator, $strPattern, $iCount);
  35. }
  36. public function scan(&$iIterator, $strPattern = null, $iCount = null)
  37. {
  38. $this->ready ?: $this->ready = $this->initializer->__invoke($this->redis);
  39. return $this->redis->scan($iIterator, $strPattern, $iCount);
  40. }
  41. public function sscan($strKey, &$iIterator, $strPattern = null, $iCount = null)
  42. {
  43. $this->ready ?: $this->ready = $this->initializer->__invoke($this->redis);
  44. return $this->redis->sscan($strKey, $iIterator, $strPattern, $iCount);
  45. }
  46. public function zscan($strKey, &$iIterator, $strPattern = null, $iCount = null)
  47. {
  48. $this->ready ?: $this->ready = $this->initializer->__invoke($this->redis);
  49. return $this->redis->zscan($strKey, $iIterator, $strPattern, $iCount);
  50. }
  51. }