$db_host = 'localhost'; $db_port = 8098; $user = $PHP_AUTH_USER; //Init $key = 'root'; $error = ''; if (isset($_GET['key'])) { $key = $_GET['key']; } if (isset($_GET['bucket'])) { $db_bucket = $_GET['bucket']; } //Connect require_once 'riak.php'; $client = new RiakClient($db_host, $db_port); if (!$client->isAlive()) { die("<tt><h1>No Riak is running on http://{$db_host}:{$db_port}/ !</h1></tt>"); } $bucket = $client->bucket($db_bucket); $db_lastkey = 'lastkey'; function base36_inc(&$num) { return $num = base_convert(base_convert($num, 36, 10) + 1, 10, 36); } if (isset($_POST['action'])) { if ($_POST['action'] === 'ADD') { $obj = $bucket->get($db_lastkey); $nextkey = $obj->getData(); while ($obj->exists()) { $obj = $bucket->get(base36_inc($nextkey)); }
<?php require_once 'config.php'; /* * ****************************************************************************** * ** NO CHANGES FROM HERE ON *** /******************************************************************************* */ $start_page = microtime(true); require_once "lib/riak-client.php"; // init the RIAK connection $riak = new RiakClient(HOST, HTTP_PORT); if (!$riak->isAlive()) { die("I couldn't ping the server. Check the HOST AND PORT settings..."); } // init the $bucket && $key if (isset($_GET['bucketName'])) { $bucket = new RiakBucket($riak, $_GET['bucketName']); $key = new RiakObject($riak, $bucket, $_GET['key']); } // delete a key if ($_GET['cmd'] == "deleteKey" && $_GET['bucketName'] && $_GET['key']) { $key->delete(); unset($_GET['key']); } // create a bucket with key=>value : "created"=>1 if ($_GET['cmd'] == 'createBucket') { if ($_POST['bucketName'] && $_POST['bucketName'] != 'Create a new bucket') { $data = array("created" => 1); $bucket = new RiakBucket($riak, $_POST['bucketName']); $x = $bucket->newObject("", $data);
function testIsAlive() { $client = new RiakClient(HOST, PORT); test_assert($client->isAlive()); }