Skip to content

Commit

Permalink
existing logic no space support
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Jun 24, 2020
1 parent a5395f7 commit 642811d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/TarantoolStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,19 @@ public function delete(Key $key, ?string $token = null)
*/
public function exists(Key $key)
{
$data = $this->getSpace()
->select(Criteria::key([ (string) $key ]));
try {
$data = $this->client
->getSpace($this->space)
->select(Criteria::key([ (string) $key ]));

if (count($data)) {
[$tuple] = $data;
return $tuple[1] == $this->getUniqueToken($key)
&& $tuple[2] >= microtime(true);
if (count($data)) {
[$tuple] = $data;
return $tuple[1] == $this->getUniqueToken($key)
&& $tuple[2] >= microtime(true);
}
} catch (RequestFailed $e) {
// query failure means there is no valid space
// it means that key is not exists in store
}
return false;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/TarantoolStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,16 @@ public function testExpiredKeyOverwrite()
$this->assertFalse($store->exists($key1));
$this->assertTrue($store->exists($key2));
}

public function testExistsOnDroppedSpace()
{
$key = new Key(uniqid(__METHOD__, true));

$store = $this->getStore();
$store->save($key);

$this->schema->tearDown();

$this->assertFalse($store->exists($key));
}
}

0 comments on commit 642811d

Please sign in to comment.