承接 php-riak/riak-client 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

php-riak/riak-client

Composer 安装命令:

composer require php-riak/riak-client

包简介

PHP Riak Client for PHP 5.4

README 文档

README

Build Status Coverage Status

A PHP client for Riak.

Installation

Run the following composer command:

$ composer require "php-riak/riak-client"

Documentation

API documentation for this library can be found on readthedocs

Overview

Getting started with the php riak client.

The easiest way to get started with the client is using a RiakClientBuilder :

use Riak\Client\RiakClientBuilder;

$builder = new RiakClientBuilder();
$client  = $builder
    ->withNodeUri('proto://192.168.1.1:8087')
    ->withNodeUri('proto://192.168.1.2:8087')
    ->withNodeUri('proto://192.168.1.3:8087')
    ->build();

Once you have a $client, commands from the Riak\Client\Command* namespace are built then executed by the client.

Some basic examples of building and executing these commands is shown below.

Getting Data In

use Riak\Client\Command\Kv\StoreValue;
use Riak\Client\Core\Query\RiakObject;
use Riak\Client\Core\Query\RiakLocation;
use Riak\Client\Core\Query\RiakNamespace;

$object    = new RiakObject();
$namespace = new RiakNamespace('bucket_type', 'bucket_name');
$location  = new RiakLocation($namespace, 'object_key');

$object->setValue('[1,1,1]');
$object->setContentType('application/json');

// store object
$store    = StoreValue::builder($location, $object)
    ->withPw(1)
    ->withW(2)
    ->build();

$client->execute($store);

Getting Data Out

use Riak\Client\Command\Kv\FetchValue;
use Riak\Client\Core\Query\RiakObject;
use Riak\Client\Core\Query\RiakLocation;
use Riak\Client\Core\Query\RiakNamespace;

$namespace = new RiakNamespace('bucket_type', 'bucket_name');
$location  = new RiakLocation($namespace, 'object_key');

// fetch object
$fetch  = FetchValue::builder($location)
    ->withNotFoundOk(true)
    ->withR(1)
    ->build();

$result = $client->execute($fetch);
$object = $result->getValue();

Removing Data

use Riak\Client\Command\Kv\DeleteValue;
use Riak\Client\Core\Query\RiakObject;
use Riak\Client\Core\Query\RiakLocation;
use Riak\Client\Core\Query\RiakNamespace;

$namespace = new RiakNamespace('bucket_type', 'bucket_name');
$location  = new RiakLocation($namespace, 'object_key');

// delete object
$delete  = DeleteValue::builder($location)
    ->withPw(1)
    ->withW(2)
    ->build();

$this->client->execute($delete);

Merging siblings

Siblings are an important feature in Riak, for this purpose we have the interface Riak\Client\Resolver\ConflictResolver, you implement this interface to resolve siblings into a single object.

Below is a simple example that will just merge the content of siblings :

use \Riak\Client\Resolver\ConflictResolver;
use \Riak\Client\Core\Query\RiakObject;
use \Riak\Client\Core\Query\RiakList;

class MySimpleResolver implements ConflictResolver
{
    /**
     * {@inheritdoc}
     */
    public function resolve(RiakList $siblings)
    {
        $result  = new MyDomainObject();
        $content = "";

        /** @var $object \MyDomainObject */
        foreach ($siblings as $object) {
            $content .= $object->getValue();
        }

        $result->setValue($content);

        return $result;
    }
}

// register your resolver during the application start up
/** @var $builder \Riak\Client\RiakClientBuilder */
$client = $builder
    ->withConflictResolver('MyDomainObject' new MySimpleResolver())
    ->withNodeUri('http://localhost:8098')
    ->build();

// fetch the object and resolve any possible conflict
$namespace = new RiakNamespace('bucket_type', 'bucket_name');
$location  = new RiakLocation($namespace, 'object_key');
$fetch     = FetchValue::builder($location)
    ->withNotFoundOk(true)
    ->withR(1)
    ->build();

/** @var $domain \MyDomainObject */
$result = $client->execute($fetch);
$domain = $result->getValue('MyDomainObject');

Performance

This library is faster than most riak clients written in php, It is about 50% percent faster is some cases, mostly because it uses protocol buffer and and iterators every where it is possible.

For more details and riak clients performance comparison see : https://github.com/FabioBatSilva/riak-clients-performance-comparison

Unit & Integration Tests

We want to ensure that all code that is included in a release has proper coverage with unit tests. It is expected that all pull requests that include new classes or class methods have appropriate unit tests included with the PR.

Running Tests

Before running the functional tests set up your riak cluster:

  • Create and activate the following types :
riak-admin bucket-type create counters '{"props":{"datatype":"counter"}}'
riak-admin bucket-type create maps '{"props":{"datatype":"map"}}'
riak-admin bucket-type create sets '{"props":{"datatype":"set"}}'
riak-admin bucket-type activate counters
riak-admin bucket-type activate maps
riak-admin bucket-type activate sets
  • Enable search capabilities in your riak.conf:
search = on

We also expect that before submitting a pull request, that you have run the tests to ensure that all of them continue to pass after your changes.

To run the tests, clone this repository and run composer update from the repository root, then you can execute all the tests by simply running php vendor/bin/phpunit.

  • To execute tests, run ./vendor/bin/phpunit
  • To check code standards, run ./vendor/bin/phpcs -p --extensions=php --standard=ruleset.xml src

php-riak/riak-client 适用场景与选型建议

php-riak/riak-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22.45k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2015 年 01 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「nosql」 「database」 「client」 「riak」 「driver」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 php-riak/riak-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 php-riak/riak-client 我们能提供哪些服务?
定制开发 / 二次开发

基于 php-riak/riak-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 22.45k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 4
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 5
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-27