コード例 #1
0
 /**
  * Garbage collector
  * 
  * This runs a map on the cluster to get the keys of sessions that haven't
  * been modified in $maxLifetime seconds and then deletes them.
  *
  * @param integer $maxLifetime session.gc_maxlifetime value
  * 
  * @return boolean
  */
 public function gc($maxLifetime)
 {
     $arg = time() - $maxLifetime;
     $function = "\n        function(value, keyData, arg) {\n            var data = Riak.mapValuesJson(value)[0];\n            if (data.atime == undefined\n                || data.data == undefined\n                || data.atime < arg) {\n                return [value.key];\n            }\n            return [];\n          }";
     $result = $this->_client->add($this->_settings['bucket'])->map($function, array('arg' => $arg, 'keep' => true))->run();
     foreach ($result as $id) {
         $this->destroy($id);
     }
     return true;
 }
コード例 #2
0
ファイル: index.php プロジェクト: pentium10/riak-admin
<?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);
コード例 #3
0
ファイル: kybca-mini.php プロジェクト: Harvie/Kyberia
$db_bucket = 'kybca-mini';
$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));
コード例 #4
0
ファイル: riak-hello.php プロジェクト: Harvie/Kyberia
<tt><h1>Riak Hello World!</h1><pre>
<?php 
require_once 'riak.php';
$client = new RiakClient('localhost', 8098);
$bucket = $client->bucket('harvie');
$obj = $bucket->newObject('foo', 'bar baz');
$obj->store();
$obj = $bucket->get('foo2');
$obj->exists();
$obj->getBucket()->getName();
print_r('key: ' . $obj->getKey() . "\n");
print_r('val: ' . $obj->getData() . "\n");
echo "\nEOF\n";
コード例 #5
0
ファイル: unit_tests.php プロジェクト: pcdinh/riak-php-client
function testLinkWalking()
{
    # Create the object...
    $client = new RiakClient(HOST, PORT);
    $bucket = $client->bucket("bucket");
    $bucket->newObject("foo", 2)->addLink($bucket->newObject("foo1", "test1")->store())->addLink($bucket->newObject("foo2", "test2")->store(), "tag")->addLink($bucket->newObject("foo3", "test3")->store(), "tag2!@#\$%^&*")->store();
    $obj = $bucket->get("foo");
    $results = $obj->link("bucket")->run();
    test_assert(count($results) == 3);
    $results = $obj->link("bucket", "tag")->run();
    test_assert(count($results) == 1);
}
コード例 #6
0
ファイル: unit_tests.php プロジェクト: tickbw/riak-php-client
function testMetaData()
{
    $client = new RiakClient(HOST, PORT);
    $bucket = $client->bucket("metatest");
    # Set some meta
    $bucket->newObject("metatest", array("foo" => 'bar'))->setMeta("foo", "bar")->store();
    # Test that we load the meta back
    $object = $bucket->get("metatest");
    test_assert($object->getMeta("foo") == "bar");
    # Test that the meta is preserved when we rewrite the object
    $bucket->get("metatest")->store();
    $object = $bucket->get("metatest");
    test_assert($object->getMeta("foo") == "bar");
    # Test that we remove meta
    $object->removeMeta("foo")->store();
    $anotherObject = $bucket->get("metatest");
    test_assert($anotherObject->getMeta("foo") === null);
}