|
add(docid, docdata [, expiry])
The add() function works different to set(). With add() the operation will fail if the document ID you specify already exists. For example, in the code below, the first operation will complete successfully, the second will fail:
$cb->add('message', 'Hello World!');
$cb->add('message', 'I pushed the button, but nothing happened!');
The add() function is useful when you are storing data into the database for the first time. For example, consider storing user data using the email address as the document ID. Using set() would overwrite an old user record. Using add() would fail the registration and indicate the user should use the password recovery system.
The add() function is also atomic, so multiple writers can be adding data to the cluster at the same time, and it’s safe to use within a multi-threaded environment.
Regardless of how you store the data, the actual format of the information you are storing is also important. |
|