Skip to content

Latest commit

 

History

History
72 lines (50 loc) · 2.53 KB

aerospike_increment.md

File metadata and controls

72 lines (50 loc) · 2.53 KB

Aerospike::increment

Aerospike::increment - increments a numeric value in a bin

Description

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').

Parameters

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

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