Flexihash\Flexihash::lookup PHP Method

lookup() public method

Looks up the target for the given resource.
public lookup ( string $resource ) : string
$resource string
return string
    public function lookup($resource)
    {
        $targets = $this->lookupList($resource, 1);
        if (empty($targets)) {
            throw new Exception('No targets exist');
        }
        return $targets[0];
    }

Usage Example

Example #1
0
 public function testFallbackPrecedenceWhenServerRemoved()
 {
     $mockHasher = new MockHasher();
     $hashSpace = new Flexihash($mockHasher, 1);
     $mockHasher->setHashValue(10);
     $hashSpace->addTarget('t1');
     $mockHasher->setHashValue(20);
     $hashSpace->addTarget('t2');
     $mockHasher->setHashValue(30);
     $hashSpace->addTarget('t3');
     $mockHasher->setHashValue(15);
     $this->assertEquals($hashSpace->lookup('resource'), 't2');
     $this->assertEquals($hashSpace->lookupList('resource', 3), ['t2', 't3', 't1']);
     $hashSpace->removeTarget('t2');
     $this->assertEquals($hashSpace->lookup('resource'), 't3');
     $this->assertEquals($hashSpace->lookupList('resource', 3), ['t3', 't1']);
     $hashSpace->removeTarget('t3');
     $this->assertEquals($hashSpace->lookup('resource'), 't1');
     $this->assertEquals($hashSpace->lookupList('resource', 3), ['t1']);
 }
All Usage Examples Of Flexihash\Flexihash::lookup