Riak: getting multiple items quickly

Say I have this array in PHP.

$ids = [
    246,
    8362,
    5241,
    2586,
    6548,
    9372,
    28504,
    14,
    5729
];

These array elements correspond to the elements in the "articles" in the bucket, and sometimes this array can be approximately 1000 elements.

I am currently viewing all of them and pulling data from 1 on 1.

$articles = [];
foreach($ids as $id)
{
    $articles[] = Riak::get("articles.$id");
}

This is more time than I would like to spend when the identifier lists become quite long.

Is there a faster way to get a list of items from a Riak bucket? I looked around a bit, and reducing the map is useful, but apparently causes more overhead than I would save with consecutive GET requests.

+3
source share
2 answers

Riak, , , . multi-get , , , , PHP.

mapreduce , , . Mapreduce , .

, , , , -, .

, , . , , . , , , , .

- - . , , , , .

Riak , , , .

+2

https://github.com/basho/riak-php-client PHP:

/**
     * Retrieve JSON-encoded objects from Riak.
     * @param  array(int) $keys - List of the key.
     * @return RiakObjects
     */
    public function multiGet($keys) {
        if (!$keys || !count($keys))
            return array();
        $query = null;
        foreach ($keys as $key) {
            if ($query) {
                $query->add($this->getBucketName(), $key);
            } else {
                $query = $this->riak->add($this->getBucketName(), $key);
            }
        }
        $results = $query->map(('function(riakObject){return [{"key":riakObject.key, "document":riakObject.values}];}'))->run();
        if (!$results || !count($results)) {
            return array();
        }

        $objects = array();
        foreach ($results as $data) {
            if (isset($data->key) && isset($data->document[0]->data) && !empty($data->document[0]->data)) {
                $object = json_decode($data->document[0]->data, true);
                if ($object) {
                    $objects[$data->key] = $object;
                }
            }
        }
        return $objects;
    }
+1

All Articles