Aerospike::touch - touch a record in the Aerospike DB
public int Aerospike::touch ( array $key, int $ttl = 0 [, array $options ] )
Aerospike::touch() will touch the given record, resetting its time-to-live and incrementing its generation.
key the key for the record. An array with keys ['ns','set','key'] or ['ns','set','digest'].
ttl the time-to-live in seconds for the record.
options including
- Aerospike::OPT_WRITE_TIMEOUT
- Aerospike::OPT_POLICY_RETRY
- Aerospike::OPT_POLICY_KEY
- Aerospike::OPT_POLICY_GEN
- Aerospike::OPT_POLICY_REPLICA
- Aerospike::OPT_POLICY_CONSISTENCY
- Aerospike::OPT_POLICY_COMMIT_LEVEL
Returns an integer status code. Compare to the Aerospike class status constants. When non-zero the Aerospike::error() and Aerospike::errorno() methods can be used.
<?php
$config = ["hosts" => [["addr"=>"localhost", "port"=>3000]], "shm"=>[]];
$client = new Aerospike($config, true);
if (!$client->isConnected()) {
echo "Aerospike failed to connect[{$client->errorno()}]: {$client->error()}\n";
exit(1);
}
$key = $client->initKey("test", "users", 1234);
$status = $client->touch($key, 120);
if ($status == Aerospike::OK) {
echo "Added 120 seconds to the record's expiration.\n"
} elseif ($status == Aerospike::ERR_RECORD_NOT_FOUND) {
echo "A user with key ". $key['key']. " does not exist in the database\n";
} else {
echo "[{$client->errorno()}] ".$client->error();
}
?>
We expect to see:
Added 120 seconds to the record's expiration.
or
A user with key 1234 does not exist in the database.