php-riak/riak-client
Composer 安装命令:
composer require php-riak/riak-client
包简介
PHP Riak Client for PHP 5.4
README 文档
README
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 php-riak/riak-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
The DreamFactory(tm) CouchDB Service.
Store your language lines in the database, yaml or other sources
The CodeIgniter Redis package
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Symfony lock Tarantool store
统计信息
- 总下载量: 22.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 4
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-27