Description
For the following code piece:
$key = 'key'; |
|
try { |
$collection->remove($key);
|
} catch (Exception $e) { |
// Ignore. |
}
|
|
$options = new Couchbase\UpsertOptions(); |
$options->expiry((new DateTimeImmutable())->modify('+5 seconds')); |
$collection->upsert($key, 'dummy', $options); |
echo $collection->get($key)->content(), PHP_EOL;
|
|
sleep(7); |
|
echo $collection->get($key)->content(), PHP_EOL;
|
It prints out an exception message when executed (as expected):
dummyFatal error: Uncaught Couchbase\Exception\DocumentNotFoundException: document_not_found (101): "unable to execute KV operation "document_get"" in /var/www/couchbase-4.1.6/src/wrapper/connection_handle.cxx:499 |
Stack trace:
|
#0 /var/www/vendor/couchbase/couchbase/Couchbase/Collection.php(124): Couchbase\Extension\documentGet(Resource id #25, 'test', '_default', '_default', 'key', Array) |
#1 /var/www/temp/examples/upsert4-1.php(36): Couchbase\Collection->get('key') |
#2 {main} |
thrown in /var/www/couchbase-4.1.6/src/wrapper/connection_handle.cxx on line 499 |
Now, if we use method upsertMulti() instead of upsert():
$key = 'key'; |
|
try { |
$collection->remove($key);
|
} catch (Exception $e) { |
// Ignore. |
}
|
|
$options = new Couchbase\UpsertOptions(); |
$options->expiry((new DateTimeImmutable())->modify('+5 seconds')); |
$collection->upsertMulti([[$key, 'dummy']], $options); |
echo $collection->get($key)->content(), PHP_EOL;
|
|
sleep(7); |
|
echo $collection->get($key)->content(), PHP_EOL;
|
|
It prints out the following message without any exception thrown out:
dummy
|
dummy
|
The only difference between the two code pieces is that we changed
$collection->upsert($key, 'dummy', $options); |
to
$collection->upsertMulti([[$key, 'dummy']], $options); |