PHPackages                             kbrw/riak-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. kbrw/riak-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

kbrw/riak-bundle
================

Allows your application to intereact with Riak datastorage

1.6.0(11y ago)1512.0k8ApachePHPPHP &gt;=5.3.2

Since Jan 5Pushed 11y ago5 watchersCompare

[ Source](https://github.com/remialvado/RiakBundle)[ Packagist](https://packagist.org/packages/kbrw/riak-bundle)[ Docs](https://github.com/remialvado/RiakBundle)[ RSS](/packages/kbrw-riak-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (16)Versions (27)Used By (0)

[![Build Status](https://camo.githubusercontent.com/ce5d66ce6b55d2748c00d834b66c6431975b36ff7dcf161aea1f2c7e6551370b/68747470733a2f2f7472617669732d63692e6f72672f72656d69616c7661646f2f5269616b42756e646c652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/remialvado/RiakBundle)

Table Of Content
================

[](#table-of-content)

- [Features](#features)
- [Roadmap](#roadmap)
- [Dependencies](#dependencies)
- [Installation](#installation)
- [Configuration](#configuration)
- [Basic Usage](#basic-usage)
    - [Accessing a Cluster](#accessing-a-cluster)
    - [Defining Bucket content](#defining-bucket-content)
    - [Insert or Update Data into a Bucket](#insert-or-update-data-into-a-bucket)
    - [Fetch Data from a Bucket](#fetch-data-from-a-bucket)
    - [Delete Data from a Bucket](#delete-data-from-a-bucket)
    - [List keys inside a Bucket](#list-keys-inside-a-bucket)
    - [Count keys inside a Bucket](#count-keys-inside-a-bucket)
    - [Search items inside a Bucket using Riak Search](#search-items-inside-a-bucket-using-riak-search)
    - [Perform MapReduce request on a Cluster](#perform-mapreduce-request-on-a-cluster)
    - [Exceptions](#exceptions)
- [Extended Usage](#extended-usage)
    - [Load and edit Bucket configuration](#load-and-edit-bucket-configuration)
    - [Enable Automatic Indexation](#enable-automatic-indexation)
    - [Play with Headers](#play-with-headers)
    - [Define your own bucket class](#define-your-own-bucket-class)
- [Admin Tasks](#admin-tasks)
    - [Common Options](#common-options)
    - [List existing buckets](#list-existing-buckets)
    - [Delete all buckets](#delete-all-buckets)
    - [List keys inside a bucket](#list-keys-inside-a-bucket)
    - [Count keys inside a bucket](#count-keys-inside-a-bucket)
    - [Delete all keys inside a bucket](#delete-all-keys-inside-a-bucket)
    - [Delete one key inside a bucket](#delete-one-key-inside-a-bucket)

Features
--------

[](#features)

RiakBundle is designed to ease interaction with [Riak](http://basho.com/products/riak-overview/) database. It allows developers to focus on stored objects instead of on communication APIs. Supported features are :

- support for multi-clustering
- configure clusters : protocol, domain, port, maximum supported connections in parallel, buckets list, ...
- allow developers to plus directly some code into Guzzle to : use proxy, log or count all calls, ...
- insert, delete and fetch objects into a bucket with support for parallel calls (curl\_multi)
- fetch, edit and save bucket properties
- list and count keys inside a bucket
- search on a bucket
- perform mapreduce operations through a fluid interface
- console tasks to list and count keys inside a bucket, delete a single key or an entire bucket
- support for custom search parameters (used by custom Riak Search builds)
- support for Bucket inheritance to allow you to define custom services on a bucket

Roadmap
-------

[](#roadmap)

- support for Secondary indexes insert and fetch operations
- support for extended bucket settings (n\_val, ...) in YAML configuration
- performance dashboard added to Symfony Debug Toolbar

Dependencies
------------

[](#dependencies)

RiakBundles requires some other bundles / libraries to work :

- Guzzle : to handle HTTP requests thru curl
- JMSSerializer : to handle serialization operations

Installation
------------

[](#installation)

Only installation using composer is supported at the moment but source code could be easily tweaked to be used outside it. In order to install RiakBundle in a classic symfony project, just update your composer.json and add or edit this lines :

```
"kbrw/riak-bundle": "1.0.*"
```

You may also need to adjust the "minimum-stability" to "dev" in your composer.json to make this work.

Then, you just need to add some bundle into your app/AppKernel.php :

```
new JMS\SerializerBundle\JMSSerializerBundle(),
new Kbrw\RiakBundle\RiakBundle(),
```

Configuration
-------------

[](#configuration)

For the next sections, let's assume your infrastructure is made of 2 Riak clusters : one used to store your backend objects and one to store all logs. The backend cluster contains two pre-defined buckets. One to store some users in JSON and one to store some cities in XML. On the log cluster, you create a new bucket every day(I know it's strange but why not...) so you can't pre-configured buckets in this cluster. Moreover, you have conducted robustness campaigns and you know that backend cluster is able to support up to 500 parallels connection where your Frontend is never hitted by more than 5 connections in parallels. So you know that you can send 100 backend requests in parallels per frontend requests but no more. If you try to store or fetch or delete more than 100 objects at once, only the first 100 will be processed. Others will have to wait for a slot to opened. RiakBundle will handle this slot mecanism for you.

All configuration can be made on config.yml file under a new `riak` namespace. With that in mind, you should define the following configuration :

Example :

```
riak:
  clusters:
    backend:
      domain: "127.0.0.1"
      port: "8098"
      client_id: "frontend"
      max_parallel_calls: 100
      buckets:
        users:
          fqcn: 'MyCompany\MyBundle\Model\User'
          format: json
        cities:
          fqcn: 'MyCompany\MyBundle\Model\City'
          format: xml
    log:
      domain: "127.0.0.1"
      port: "8099"
      client_id: "frontend"
```

Basic Usage
-----------

[](#basic-usage)

### Accessing a cluster

[](#accessing-a-cluster)

Each cluster becomes a service called "riak.cluster.". In our example, you can access your two clusters using :

```
$backendCluster = $container->get("riak.cluster.backend");
$logCluster = $container->get("riak.cluster.log");
```

### Defining bucket content

[](#defining-bucket-content)

Riak stores text-based objects so you need to provide a text-based version of your objects. The best practice we recommand is to create an annotated object which represent your model. For example, an User class could be implemented this way :

```
