/** * Returns a list of nodes from the hashring. * * @param IDistributionStrategy $ring Hashring instance. * @param int $iterations Number of nodes to fetch. * @return array Nodes from the hashring. */ protected function getNodes(IDistributionStrategy $ring, $iterations = 10) { $nodes = array(); for ($i = 0; $i < $iterations; $i++) { $key = $ring->generateKey($i * $i); $nodes[] = $ring->get($key); } return $nodes; }
public function getHash(IDistributionStrategy $distributor) { if (isset($this->_hash)) { return $this->_hash; } else { if (isset($this->_arguments[0])) { // TODO: should we throw an exception if the command does // not support sharding? $key = $this->_arguments[0]; $start = strpos($key, '{'); $end = strpos($key, '}'); if ($start !== false && $end !== false) { $key = substr($key, ++$start, $end - $start); } $this->_hash = $distributor->generateKey($key); return $this->_hash; } } return null; }