Skip to content

Latest commit

 

History

History
74 lines (54 loc) · 2.58 KB

aerospike_touch.md

File metadata and controls

74 lines (54 loc) · 2.58 KB

Aerospike::touch

Aerospike::touch - touch a record in the Aerospike DB

Description

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.

Parameters

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

Return Values

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.

Examples

<?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.

See Also