start2004/riak-php-client

PHP7的Riak非官方客户端,合并`basho/riak-pb`和`open-adapter/riak-php-client`,修复错误“不能使用Riak\Object作为Object,因为'Object'是一个特殊类名”,支持8087或8098。

3.5.3.1 2021-01-22 08:55 UTC

README

Packagist

Riak PHP客户端是一个库,它使得与Riak(一个开源、分布式数据库,专注于高可用性、水平扩展和可预测的延迟)进行通信变得容易。这个库通过cURL扩展与Riak的HTTP接口通信。如果您想通过Protocol Buffers接口与Riak通信,请使用官方PHP PB客户端。Riak和这个库都由Basho Technologies维护。

要查看其他可用于Riak的客户端,请访问我们的文档网站

  1. 安装
  2. 文档
  3. 贡献
  4. 路线图
  5. 许可和作者

安装

依赖

Composer安装

此库已添加到Packagist以简化安装过程。运行以下composer命令

$ composer require "start2004/riak-php-client": "3.*"

或者,手动将以下内容添加到您的composer.json文件中的require部分

"require": {
    "start2004/riak-php-client": "3.*"
}

然后运行composer update以确保模块已安装。

文档

此库的API文档的完整可遍历版本可在Github Pages上找到。

示例用法

以下是一个使用此客户端的简短示例。更多示例代码可在示例中找到。

8087

需要allegro/protobuf:>= 0.12.3,docker-php-ext-install protobuf

https://packagist.org.cn/packages/allegro/php-protobuf

https://github.com/allegro/php-protobuf

die("This is a stub file for IDEs, don't use it directly!");

abstract class ProtobufMessage
{
    ...
}
代码
// lib classes are included via the Composer autoloader files
use Start2004\Riak;
use Start2004\Riak\Node;
use Start2004\Riak\Command;

// define the connection info to our Riak nodes
$node = (new Node\Builder)
    ->atHost('riak domain')
    ->onPort(8087)
    ->build();

// instantiate the Riak client
$riak = new Riak([$node], [], new Riak\Api\Pb());
$bucket = new Riak\Bucket("bucket name");

// location
$location = new Riak\Location("key name", $bucket);

// dataObject
$dataObject = new Riak\DataObject("store data");
$dataObject->setContentType("text/html");
$dataObject->setContentEncoding("identity");

// build a command to be executed against Riak
$command = (new Command\Builder\StoreObject($riak))
    ->withObject($dataObject)
    ->atLocation($location);

// store
$store = new Command\DataObject\Store($command);
    
// Receive a response object
$response = $store->execute();



// fetch object
$command = (new Command\Builder\FetchObject($riak))
    ->atLocation($location)
    ->build();
$response = $command->execute();

// data
if($response->getCode() == "200"){
    $dataObject = $response->getDataObject();
    $contentType = $dataObject->getContentType();
    $data = $dataObject->getData();
} else {}



// delete object
$command = (new Command\Builder\DeleteObject($riak))
    ->atLocation($location);
$delete = new Command\DataObject\Delete($command);
$response = $delete->execute();

// delete result
return !($response->getCode() === 404);

8098

// lib classes are included via the Composer autoloader files
use Start2004\Riak;
use Start2004\Riak\Node;
use Start2004\Riak\Command;

// define the connection info to our Riak nodes
$node = (new Node\Builder)
    ->atHost('riak domain')
    ->onPort(8098)
    ->build();

// instantiate the Riak client
$riak = new Riak([$node]);
$bucket = new Riak\Bucket("bucket name");

// location
$location = new Riak\Location("key name", $bucket);

// dataObject
$dataObject = new Riak\DataObject("store data");
$dataObject->setContentType("text/html");
$dataObject->setContentEncoding("identity");

// build a command to be executed against Riak
$command = (new Command\Builder\StoreObject($riak))
    ->withObject($dataObject)
    ->atLocation($location)
    ->build();

// Receive a response object
$response = $command->execute();

贡献

此存储库的维护者是Basho的工程师,我们欢迎您为此项目做出贡献!您可以从审查CONTRIBUTING.md开始,以获取有关测试到编码标准的所有信息。

一个真诚的免责声明

由于我们对稳定性的执着以及我们丰富的用户生态系统,此存储库的社区更新可能需要更长的时间进行审查。

最有帮助的贡献方式是通过问题报告您的经验。在内部审查期间,问题可能不会更新,但仍非常受珍视。

感谢您成为社区的一部分!我们为此爱您。

路线图

  • 当前的开发和master分支包含对Riak版本2.1+的功能支持
  • 2016年第二季度添加对Riak TS的支持

许可和作者

合并

活跃

原文

版权所有 (c) 2015 Basho Technologies, Inc. 根据Apache许可证第2版(“许可证”)授权。有关更多详细信息,请参阅许可证