Bravo3\Orm\Drivers\Redis\RedisDriver::retrieve PHP Method

retrieve() public method

Retrieve an object, throwing an exception if not found
public retrieve ( string $key ) : SerialisedData
$key string
return Bravo3\Orm\Drivers\Common\SerialisedData
    public function retrieve($key)
    {
        if (!$this->clientCmd('exists', [$key])) {
            throw new NotFoundException('Key "' . $key . '" does not exist');
        }
        $data = $this->clientCmd('get', [$key]);
        return new SerialisedData(substr($data, 0, 4), substr($data, 4));
    }

Usage Example

Example #1
0
 public function testClientConnectionSucceedOnSecondIteration()
 {
     $client = $this->prophesize(DummyClient::class);
     $driver = new RedisDriver(null, null, null, $client->reveal());
     $client->exists('doc:article:1')->shouldBeCalledTimes(1)->willReturn(true);
     $client->get('doc:article:1')->shouldBeCalledTimes(1)->willThrow(new \Exception());
     $client->get('doc:article:1')->shouldBeCalledTimes(1)->willReturn('Article');
     $driver->retrieve('doc:article:1');
 }