Esempio n. 1
0
// Create a key
$cb->set("mytest", 1);
echo "\n--------------\n";
echo "Get mytest: ";
echo $cb->get("mytest");
// try to add a key that exists
$result = $cb->add("mytest", 2);
if ($result) {
    echo "\n--------------\n";
    echo "Add succeeded";
} else {
    echo "\n--------------\n";
    echo "Add failed: key exists";
}
// success
$result = $cb->replace("mytest", 2);
echo "\n--------------\n";
echo "Get mytest: ";
echo $cb->get("mytest");
// try to replace a key that does not exist
$result = $cb->add("mytest4", 2);
if ($result) {
    echo "\n--------------\n";
    echo "Replace succeeded";
} else {
    echo "\n--------------\n";
    echo "Replace failed: key does not exist";
}
$cb->delete("mytest");
$result = $cb->delete("mytest3");
if ($result) {
Esempio n. 2
0
// retrieve the document and output
$doc = $cb->get($user_data1->email);
echo "\n--------------\nRetrieve Doc\n";
echo $doc;
echo "\n--------------\n";
var_dump(Person::fromJSON($doc));
$first_cas = null;
$doc = json_decode($cb->get($user_data1->email, null, $first_cas));
echo "\n--------------\nRetrieve Doc and get CAS\n";
echo "1st CAS: {$first_cas}";
echo "\n--------------\n";
echo "update doc and look at cas";
$doc->logins += 1;
echo "\n--------------\n";
echo "Logins:  {$doc->logins} \n";
$cb->replace($user_data1->email, json_encode($user_data1));
$second_cas = null;
$doc = json_decode($cb->get($user_data1->email, null, $second_cas));
echo "\n--------------\n";
echo "2nd CAS: {$second_cas}";
echo "\n--------------\n";
$i = 1;
$keys = array();
while ($i <= 9) {
    // put a gap in the list to show missing item
    if ($i != 3) {
        $cb->set("key-{$i}", json_encode(array("doctype" => "learn", "value" => $i)), 30);
    }
    $keys[$i] = "key-{$i}";
    $i++;
}
Esempio n. 3
0
 /**
  * {@inheritDoc}
  */
 public function update($storageName, $key, array $data)
 {
     $this->client->replace($key, $data);
 }
Esempio n. 4
0
$user_data1->username = "******";
$user_data1->name = "John Smith";
$user_data1->email = "*****@*****.**";
$user_data1->password = "******";
$user_data1->logins = 0;
echo "--------------------------------------------------------------------------\n";
echo "Set the Data, then Retrieve Two Copies of the Document\n";
// initialize the documents
$cb->set($user_data1->email, json_encode($user_data1));
// retrieve the document and output
$v1 = json_decode($cb->get($user_data1->email, null, $cas));
echo "--------------------------------------------------------------------------\n";
echo "CAS : {$cas}\n";
$cas1 = $cas;
$v2 = json_decode($cb->get($user_data1->email, null, $cas));
$cas2 = $cas;
echo "--------------------------------------------------------------------------\n";
echo "Both v1 and v2 are identical and have identical CAS [(cas1) {$cas1} == (cas2) {$cas2}]\n";
echo "\n--------------\n";
echo "Now We'll update the document which results in a new CAS";
$v1->logins += 1;
$cas1 = $cb->set($v1->email, json_encode($v1));
echo "Now CAS as changed [(cas1) {$cas1} != (cas2) {$cas2}]";
echo "\n\n--------------\n";
$result = $cb->replace($v2->email, json_encode($v2), 0, $cas2);
if ($result) {
    echo "Success: Replace Operation succeeded (shouldn't display)";
} else {
    echo "ERROR: Replace Operation failed due to CAS mismatch";
}
echo "\n--------------------------------------------------------------------------\n";