public function getConnectionsByKeyName($name, $count)
    {
        // If we have only one backend, return it.
        if ($this->_backendsCount == 1) {
            return array_keys($this->_backends);
        }

        if (!$this->_hashringIsInitialized) {
            $this->_initializeHashring();
            $this->_hashringIsInitialized = true;
        }

        // If the key has already been mapped, return the cached entry.
        if ($this->_cacheMax > 0 && isset($this->_cache[$name])) {
            return $this->_cache[$name];
        }

        // If $count is greater than or equal to the number of available backends, return all.
        if ($count >= $this->_backendsCount) return array_keys($this->_backends);

        // Initialize the return array.
        $return = array();

        $crc32 = crc32($name);

        // Select the slice to begin with.
        $slice = floor($crc32 / $this->_slicesDiv) + $this->_slicesHalf;

        // This counter prevents going through more than 1 loop.
        $looped = false;

        while (true) {
            // Go through the hashring, one slice at a time.
            foreach ($this->_hashring[$slice] as $position => $backend) {
                // If we have a usable backend, add to the return array.
                if ($position >= $crc32) {
                    // If $count = 1, no more checks are necessary.
                    if ($count === 1) {
                        $return = array($backend);
                        break 2;
                    } elseif (!in_array($backend, $return)) {
                        $return[] = $backend;
                        if (count($return) >= $count) break 2;
                    }

                    $return = array($backend);
                    break 1;
                }
            }

            // Continue to the next slice.
            $slice++;

            // If at the end of the hashring.
            if ($slice >= $this->_slicesCount) {
                // If already looped once, something is wrong.
                if ($looped) {
                    break;
                }

                // Otherwise, loop back to the beginning.       
                $crc32 = -2147483648;
                $slice = 0;
                $looped = true;
            }
        }

        // Cache the result for quick retrieval in the future.
        if ($this->_cacheMax > 0) {
            // Add to internal cache.
            $this->_cache[$name] = $return;
            $this->_cacheCount++;

            // If the cache is getting too big, clear it.
            if ($this->_cacheCount > $this->_cacheMax) {
                $this->_cleanCache();
            }
        }

        // Return the result.

        return $return;
    }
public function getConnectionsByKeyName($name, $count)
    {
        // If we have only one backend, return it.
        if ($this->_backendsCount == 1) {
            return array_keys($this->_backends);
        }

        if (!$this->_hashringIsInitialized) {
            $this->_initializeHashring();
            $this->_hashringIsInitialized = true;
        }

        // If the key has already been mapped, return the cached entry.
        if ($this->_cacheMax > 0 && isset($this->_cache[$name])) {
            return $this->_cache[$name];
        }

        // If $count is greater than or equal to the number of available backends, return all.
        if ($count >= $this->_backendsCount) return array_keys($this->_backends);

        // Initialize the return array.
        $return = array();

        $crc32 = crc32($name);

        // Select the slice to begin with.
        $slice = floor($crc32 / $this->_slicesDiv) + $this->_slicesHalf;

        // This counter prevents going through more than 1 loop.
        $looped = false;

        while (true) {
            // Go through the hashring, one slice at a time.
            foreach ($this->_hashring[$slice] as $position => $backend) {
                // If we have a usable backend, add to the return array.
                if ($position >= $crc32) {
                    // If $count = 1, no more checks are necessary.
                    if ($count === 1) {
                        $return = array($backend);
                        break 2;
                    } elseif (!in_array($backend, $return)) {
                        $return[] = $backend;
                        if (count($return) >= $count) break 2;
                    }

                    $return = array($backend);
                    break 1;
                }
            }

            // Continue to the next slice.
            $slice++;

            // If at the end of the hashring.
            if ($slice >= $this->_slicesCount) {
                // If already looped once, something is wrong.
                if ($looped) {
                    break;
                }

                // Otherwise, loop back to the beginning.       
                $crc32 = -2147483648;
                $slice = 0;
                $looped = true;
            }
        }

        // Cache the result for quick retrieval in the future.
        if ($this->_cacheMax > 0) {
            // Add to internal cache.
            $this->_cache[$name] = $return;
            $this->_cacheCount++;

            // If the cache is getting too big, clear it.
            if ($this->_cacheCount > $this->_cacheMax) {
                $this->_cleanCache();
            }
        }

        // Return the result.

        return $return;
    }
public function getConnectionsByKeyName ( $ name , $ count ) { // If we have only one backend, return it. if ( $ this -> _backendsCount == 1 ) { return array_keys ( $ this -> _backends ) ; } if ( ! $ this -> _hashringIsInitialized ) { $ this -> _initializeHashring ( ) ; $ this -> _hashringIsInitialized = true ; } // If the key has already been mapped, return the cached entry. if ( $ this -> _cacheMax > 0 && isset ( $ this -> _cache [ $ name ] ) ) { return $ this -> _cache [ $ name ] ; } // If $count is greater than or equal to the number of available backends, return all. if ( $ count >= $ this -> _backendsCount ) return array_keys ( $ this -> _backends ) ; // Initialize the return array. $ return = array ( ) ; $ crc32 = crc32 ( $ name ) ; // Select the slice to begin with. $ slice = floor ( $ crc32 / $ this -> _slicesDiv ) + $ this -> _slicesHalf ; // This counter prevents going through more than 1 loop. $ looped = false ; while ( true ) { // Go through the hashring, one slice at a time. foreach ( $ this -> _hashring [ $ slice ] as $ position => $ backend ) { // If we have a usable backend, add to the return array. if ( $ position >= $ crc32 ) { // If $count = 1, no more checks are necessary. if ( $ count === 1 ) { $ return = array ( $ backend ) ; break 2 ; } elseif ( ! in_array ( $ backend , $ return ) ) { $ return [ ] = $ backend ; if ( count ( $ return ) >= $ count ) break 2 ; } $ return = array ( $ backend ) ; break 1 ; } } // Continue to the next slice. $ slice ++ ; // If at the end of the hashring. if ( $ slice >= $ this -> _slicesCount ) { // If already looped once, something is wrong. if ( $ looped ) { break ; } // Otherwise, loop back to the beginning.        $ crc32 = - 2147483648 ; $ slice = 0 ; $ looped = true ; } } // Cache the result for quick retrieval in the future. if ( $ this -> _cacheMax > 0 ) { // Add to internal cache. $ this -> _cache [ $ name ] = $ return ; $ this -> _cacheCount ++ ; // If the cache is getting too big, clear it. if ( $ this -> _cacheCount > $ this -> _cacheMax ) { $ this -> _cleanCache ( ) ; } } // Return the result. return $ return ; }
Get a list of connections by key name

@param string $name Key name
@param int $requestedCount The length of the list to return
@return array List of connections
Get a list of connections by key name