Esempio n. 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;
 }
Esempio n. 2
0
function testErlangMapReduce()
{
    # Create the object...
    $client = new RiakClient(HOST, PORT);
    $bucket = $client->bucket("bucket");
    $bucket->newObject("foo", 2)->store();
    $bucket->newObject("bar", 2)->store();
    $bucket->newObject("baz", 4)->store();
    # Run the map...
    $result = $client->add("bucket", "foo")->add("bucket", "bar")->add("bucket", "baz")->map(array("riak_mapreduce", "map_object_value"))->reduce(array("riak_mapreduce", "reduce_set_union"))->run();
    test_assert(count($result) == 2);
}
Esempio n. 3
0
function testSecondaryIndexMapReduce()
{
    $client = new RiakClient(HOST, PORT);
    $bucket = $client->bucket("index-mapred-test");
    # Setup
    $bucket->newObject("one", array("foo" => 1, "bar" => "red"))->addIndex("number", "int", 1)->addIndex("text", "bin", "apple")->addAutoIndex("foo", "int")->addAutoIndex("bar", "bin")->store();
    $bucket->newObject("two", array("foo" => 2, "bar" => "green"))->addIndex("number", "int", 2)->addIndex("text", "bin", "avocado")->addAutoIndex("foo", "int")->addAutoIndex("bar", "bin")->store();
    $bucket->newObject("three", array("foo" => 3, "bar" => "blue"))->addIndex("number", "int", 3)->addIndex("text", "bin", "blueberry")->addAutoIndex("foo", "int")->addAutoIndex("bar", "bin")->store();
    $bucket->newObject("four", array("foo" => 4, "bar" => "orange"))->addIndex("number", "int", 4)->addIndex("text", "bin", "citrus")->addAutoIndex("foo", "int")->addAutoIndex("bar", "bin")->store();
    $bucket->newObject("five", array("foo" => 5, "bar" => "yellow"))->addIndex("number", "int", 5)->addIndex("text", "bin", "banana")->addAutoIndex("foo", "int")->addAutoIndex("bar", "bin")->store();
    $bucket->newObject("six", array("foo" => 6, "bar" => "purple"))->addIndex("number", "int", 6)->addIndex("number", "int", 7)->addIndex("number", "int", 8)->setIndex("text", "bin", array("x", "y", "z"))->store();
    # Test
    $result = $client->add($bucket->getName())->indexSearch('number', 'int', 6)->run();
    test_assert(count($result) == 1);
    $result = $client->add($bucket->getName())->indexSearch('number', 'int', 9)->run();
    test_assert(count($result) == 0);
    $result = $client->add($bucket->getName())->indexSearch('text', 'bin', 'banana')->run();
    test_assert(count($result) == 1);
    # Test ranges
    $result = $client->add($bucket->getName())->indexSearch('number', 'int', 1, 4)->run();
    test_assert(count($result) == 4);
    $result = $client->add($bucket->getName())->indexSearch('number', 'int', 6, 8)->run();
    # I'm not convinced this result is correct, a range
    # search matching multiple values of the same index
    # on the same document should return that document
    # multiple times?  Nonetheless it's consistent with
    # direct index search against the bucket, and the
    # problem would come out of the way Riak does index
    # searches on the server.
    test_assert(count($result) == 3);
}
Esempio n. 4
0
function testKeyFilterOperator()
{
    # Create the object...
    $client = new RiakClient(HOST, PORT);
    $bucket = $client->bucket("filter_bucket");
    $bucket->newObject("foo_one", array("foo" => "one"))->store();
    $bucket->newObject("foo_two", array("foo" => "two"))->store();
    $bucket->newObject("foo_three", array("foo" => "three"))->store();
    $bucket->newObject("foo_four", array("foo" => "four"))->store();
    $bucket->newObject("moo_five", array("foo" => "five"))->store();
    $mapred = $client->add($bucket->name)->key_filter(array('starts_with', 'foo'))->key_filter_or(array('ends_with', 'five'));
    $results = $mapred->run();
    test_assert(count($results) == 5);
}