diff --git a/src/TarantoolStore.php b/src/TarantoolStore.php index bb34af6..4786e2d 100644 --- a/src/TarantoolStore.php +++ b/src/TarantoolStore.php @@ -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; } diff --git a/tests/TarantoolStoreTest.php b/tests/TarantoolStoreTest.php index 081cf0b..b14b287 100644 --- a/tests/TarantoolStoreTest.php +++ b/tests/TarantoolStoreTest.php @@ -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)); + } }