Aerospike::increment - increments a numeric value in a bin
public int Aerospike::increment ( array $key, string $bin, int $offset [, array $options ] )
Aerospike::increment() will increment a bin containing a numeric value by the offset or set it as the initial value if the record/bin does not exist.
If a record with the given key does not exist it will be initialized with one bin named bin set to the integer value offset (the so-called 'upsert').
key the key under which the record 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.
offset the integer by which to increment the 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 = array("hosts"=>array(array("addr"=>"localhost", "port"=>3000)));
$db = new Aerospike($config);
if (!$db->isConnected()) {
echo "Aerospike failed to connect[{$db->errorno()}]: {$db->error()}\n";
exit(1);
}
$key = $db->initKey("test", "users", 1234);
$options = array(Aerospike::OPT_TTL => 7200);
$status = $db->increment($key, 'pto', -4, $options);
if ($status == Aerospike::OK) {
echo "Decremented four vacation days from the user's PTO balance.\n";
} else {
echo "[{$db->errorno()}] ".$db->error();
}
?>
We expect to see:
Decremented four vacation days from the user's PTO balance.