add

(Requires Workerman version >= 3.3.0)

bool \GlobalData\Client::add(string $key, mixed $value)

Atomically adds a value. If the key already exists, it will return false.

Parameters

$key

The key value. (For example, $global->abc, where abc is the key value)

$value

The value to be stored.

Return Values

Returns true on success, or false on failure.

Example

$global = new GlobalData\Client('127.0.0.1:2207');

if($global->add('some_key', 10))
{
    // $global->some_key assignment successful
    echo "add success " , $global->some_key;
}
else
{
    // $global->some_key already exists, assignment failed
    echo "add fail " , var_export($global->some_key);
}