jiangyunan / riak
PHP官方Riak客户端
Requires
- php: >=5.4
- ext-curl: *
- ext-json: *
Requires (Dev)
- apigen/apigen: 4.1.*
- phpunit/phpunit: 4.8.*
README
支持PHP7以上,protobuf修改为Google官方protobuf
示例
官方示例,[https://docs.riak.com/riak/kv/latest/developing/getting-started/php/crud-operations/index.html](https://docs.riak.com/riak/kv/latest/developing/getting-started/php/crud-operations/index.html)
对象
use Basho\Riak; use Basho\Riak\Node; use Basho\Riak\Command; $node = (new node\Builder) ->atHost('127.0.0.1') ->onPort(8087) ->build(); $riak = new Riak([$node], [], new Riak\Api\Pb()); $bucket = new Riak\Bucket("carnoc"); $key = "date.txt"; $location = new Riak\Location($key, $bucket);
写入
对写入、读取的内容不再编码,无需设置setContentEncoding
https://github.com/jiangyunan/riak-php7/blob/main/src/Riak/Command/RObject.php#L42
$dateString = Date("H:i:s"); $dataObject = new Riak\RObject($dateString); $dataObject->setContentType("text/plain"); $storeCommand = (new Command\Builder\StoreObject($riak)) ->withObject($dataObject) ->atLocation($location) ->build(); $response = $storeCommand->execute();
读取
$fetchCommand = (new Command\Builder\FetchObject($riak)) ->atLocation($location) ->build(); $response = $fetchCommand->execute(); if($response->getCode() == 200){ $dataObject = $response->getObject(); $contentType = $dataObject->getContentType(); $data = [ "type" => $contentType, "data" => $dataObject->getData(), ]; } else { $data = []; }
删除
$deleteCommand = (new Command\Builder\DeleteObject($riak)) ->atLocation($location) ->build(); $response = $deleteCommand->execute(); return ($response->getCode() == 204);
安装
依赖
- PHP 5.4+
- PHP扩展:curl、json和openssl [protobuf的链接](https://pecl.php.net/package/protobuf)
- Riak 2.1+
Riak PHP客户端
Riak PHP客户端 是一个库,它使得与Riak进行通信变得简单,Riak是一个开源的分布式数据库,专注于高可用性、水平可扩展性和 可预测 延迟。这个库使用cURL扩展与Riak的HTTP接口通信。如果您想使用Protocol Buffers接口与Riak通信,请使用官方PHP PB客户端。Riak和这个库都由Basho Technologies维护。
要查看可用于与Riak一起使用的其他客户端,请访问我们的文档网站
安装
依赖
- PHP 5.4+
- PHP扩展:curl、json和openssl [用于安全功能]
- Riak 2.1+
- Composer PHP依赖管理器
Composer安装
此库已被添加到Packagist以简化安装过程。运行以下composer命令
$ composer require "basho/riak": "3.0.*"
或者,您可以手动将以下内容添加到您的composer.json
中的require
部分
"require": { "basho/riak": "3.0.*" }
然后运行composer update
以确保模块已安装。
文档
此库的API文档的完整可遍历版本可以在Github Pages上找到。
示例用法
以下是一个使用客户端的简短示例。更多示例代码可在示例中找到。
// lib classes are included via the Composer autoloader files use Basho\Riak; use Basho\Riak\Node; use Basho\Riak\Command; // define the connection info to our Riak nodes $nodes = (new Node\Builder) ->onPort(10018) ->buildCluster(['riak1.company.com', 'riak2.company.com', 'riak3.company.com',]); // instantiate the Riak client $riak = new Riak($nodes); // build a command to be executed against Riak $command = (new Command\Builder\StoreObject($riak)) ->buildObject('some_data') ->buildBucket('users') ->build(); // Receive a response object $response = $command->execute(); // Retrieve the Location of our newly stored object from the Response object $object_location = $response->getLocation();
贡献
此存储库的维护者是Basho的工程师,我们欢迎您对此项目的贡献!您可以首先查看CONTRIBUTING.md以获取有关从测试到编码标准的信息。
诚实的免责声明
由于我们对稳定性的执着以及我们丰富的用户生态系统,对此存储库的社区更新可能需要更长的时间进行审查。
最有帮助的贡献方式是通过问题报告您的经验。在内部审查时,问题可能不会被更新,但它们仍然非常受欢迎。
感谢您成为社区的一部分!我们为此爱您。
路线图
- 当前的开发和master分支包含对Riak版本2.1+的功能支持
- 添加对Riak TS Q2 2016的支持
许可和作者
- 作者:Christopher Mancini (https://github.com/christophermancini)
- 作者:Alex Moore (https://github.com/alexmoore)
- 作者:Luke Bakken (https://github.com/lukebakken)
版权所有(C)2015 Basho Technologies, Inc. 依照Apache License,版本2.0(以下简称“许可证”)授权。更多详情,请参阅许可证。