Aerospike::prepend - prepends a string to the string value in a bin
public int Aerospike::prepend ( array $key, string $bin, string $value [, array $options ] )
Aerospike::prepend() will prepend a string to the string value in bin. Like other bin operations, prepend() only works on existing records (i.e. ones that were previously created with a put()).
key the key under which the bin can be found. An array with keys ['ns','set','key'] or ['ns','set','digest'].
bin the name of the bin in which we have a numeric value.
value the string to prepend to the string value in the bin.
options including
- Aerospike::OPT_WRITE_TIMEOUT
- Aerospike::OPT_TTL
- 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);
$options = [Aerospike::OPT_TTL => 3600];
$status = $client->prepend($key, 'name', '*', $options);
if ($status == Aerospike::OK) {
echo "Starred the user.\n";
} else {
echo "[{$client->errorno()}] ".$client->error();
}
?>
We expect to see:
Starred the user.