DistributorInterface.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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\Distributor;
  11. use Predis\Cluster\Hash\HashGeneratorInterface;
  12. /**
  13. * A distributor implements the logic to automatically distribute keys among
  14. * several nodes for client-side sharding.
  15. *
  16. * @author Daniele Alessandri <suppakilla@gmail.com>
  17. */
  18. interface DistributorInterface
  19. {
  20. /**
  21. * Adds a node to the distributor with an optional weight.
  22. *
  23. * @param mixed $node Node object.
  24. * @param int $weight Weight for the node.
  25. */
  26. public function add($node, $weight = null);
  27. /**
  28. * Removes a node from the distributor.
  29. *
  30. * @param mixed $node Node object.
  31. */
  32. public function remove($node);
  33. /**
  34. * Returns the corresponding slot of a node from the distributor using the
  35. * computed hash of a key.
  36. *
  37. * @param mixed $hash
  38. *
  39. * @return mixed
  40. */
  41. public function getSlot($hash);
  42. /**
  43. * Returns a node from the distributor using its assigned slot ID.
  44. *
  45. * @param mixed $slot
  46. *
  47. * @return mixed|null
  48. */
  49. public function getBySlot($slot);
  50. /**
  51. * Returns a node from the distributor using the computed hash of a key.
  52. *
  53. * @param mixed $hash
  54. *
  55. * @return mixed
  56. */
  57. public function getByHash($hash);
  58. /**
  59. * Returns a node from the distributor mapping to the specified value.
  60. *
  61. * @param string $value
  62. *
  63. * @return mixed
  64. */
  65. public function get($value);
  66. /**
  67. * Returns the underlying hash generator instance.
  68. *
  69. * @return HashGeneratorInterface
  70. */
  71. public function getHashGenerator();
  72. }