/** * @param string $key * @param array|string $tags * @return bool */ protected function setTags($key, $tags) { if (!is_array($tags)) { $tags = array($tags); } foreach ($tags as $tag) { try { if (!$this->Couchbase->add($this->tag_prefix . $tag, '"' . addcslashes($key, '\\') . '"')) { $this->Couchbase->append($this->tag_prefix . $tag, ',"' . addcslashes($key, '\\') . '"'); } } catch (\Exception $Exception) { $this->ReportError('Can\'t set tag ' . $tag . ' for key ' . $key, __LINE__); } } return true; }
<?php echo "--------------------------------------------------------------------------\n"; echo "\tCouchbase Storage Operations\n"; echo "--------------------------------------------------------------------------\n"; $cb = new Couchbase(); // 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 {
/** * {@inheritDoc} */ public function insert($storageName, $key, array $data) { $this->client->add($key, $data); }