StrategyInterface.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.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 Predis\Cluster;
  11. use Predis\Cluster\Distributor\DistributorInterface;
  12. use Predis\Command\CommandInterface;
  13. /**
  14. * Interface for classes defining the strategy used to calculate an hash out of
  15. * keys extracted from supported commands.
  16. *
  17. * This is mostly useful to support clustering via client-side sharding.
  18. *
  19. * @author Daniele Alessandri <suppakilla@gmail.com>
  20. */
  21. interface StrategyInterface
  22. {
  23. /**
  24. * Returns a slot for the given command used for clustering distribution or
  25. * NULL when this is not possible.
  26. *
  27. * @param CommandInterface $command Command instance.
  28. *
  29. * @return int
  30. */
  31. public function getSlot(CommandInterface $command);
  32. /**
  33. * Returns a slot for the given key used for clustering distribution or NULL
  34. * when this is not possible.
  35. *
  36. * @param string $key Key string.
  37. *
  38. * @return int
  39. */
  40. public function getSlotByKey($key);
  41. /**
  42. * Returns a distributor instance to be used by the cluster.
  43. *
  44. * @return DistributorInterface
  45. */
  46. public function getDistributor();
  47. }