widdallc/riak-php7

PHP Riak 客户端,兼容 PHP7

dev-master 2021-02-19 22:12 UTC

This package is auto-updated.

Last update: 2024-09-26 07:14:06 UTC


README

Riak PHP 客户端 是一个客户端,用于方便地与 Riak 进行通信,Riak 是一个开源的分布式数据库,专注于高可用性、水平可扩展性和 可预测的 延迟。Riak 和此代码都由 Basho 维护。

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

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

安装

依赖

  • 2.x.x 版本 需要 PHP 5.4+
  • 1.4.x 版本 需要 PHP 5.3+

Composer 安装

运行以下 composer 命令

$ composer require "widdallc/riak-php7": "1.0.*"

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

"require": {
    "widdallc/riak-php7": "1.0.*"
}

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

文档

  • 主分支:Build Status

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

发布

此项目的发布标签与 Riak 的主版本和次版本号对齐。例如,如果您正在使用 Riak 的 1.4.9 版本,那么您将需要此库的最新 1.4.* 版本。

示例用法

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

// lib classes are included via the Composer autoloader files
use Widda\Riak;
use Widda\Riak\Node;
use Widda\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($command);

// Retrieve the Location of our newly stored object from the Response object
$object_location = $response->getLocation();

示例:存储图像

use Widda\Riak;
use Widda\Riak\Node;
use Widda\Riak\Command;

// define the connection info to our Riak nodes
$nodes = (new Node\Builder)->onPort(8098)->buildCluster('riak1.company.com');

// instantiate the Riak client
$riak = new Riak($nodes);

$url = false;
$headers = null;

$filename = 'my_file.png';
$prefix = null;

$data = file_get_contents($filename);


if(!empty($data)) {
    $contentType = 'image/png';

    if(!empty($contentType))
        $headers = ['Content-Type' => $contentType];
    	$hash = rtrim(strtr(base64_encode(sha1_file($filename, true)), '+/', '-_'), '=');
    	$key = ($prefix ? $prefix.'_' : '').$hash;

    $command = (new Command\Builder\StoreObject($riak))
    	->buildObject($data, $headers)
        ->buildLocation($key, 'MY_RIAK_BUCKET')
        ->build();

	$response = $command->execute();
	
	if($response->isSuccess()) {
    	$url = $key;
	}
	else {
    	trigger_error("Erreur Riak. Code : ".$response->getCode().", Message : ".$response->getMessage());
	}
}

示例:获取图像

use Widda\Riak;
use Widda\Riak\Node;
use Widda\Riak\Command;

// define the connection info to our Riak nodes
$nodes = (new Node\Builder)->onPort(8098)->buildCluster('riak1.company.com');

// instantiate the Riak client
$riak = new Riak($nodes);

$response = (new Command\Builder\FetchObject($riak))
            ->buildLocation('MY_KEY', 'MY_RIAK_BUCKET')
            ->build()
            ->execute();

if($response->isSuccess()) {
    $data = $response->getDataObject()->getData();  //notice ->getObject() is now ->getDataObject()

    //set the image header
    header("Content-Type", $response->getContentType());

    // display the image
    echo $data;
}

贡献

该存储库的维护者是 Basho 的工程师,我们欢迎您为此项目做出贡献!您可以首先通过审查 CONTRIBUTING.md 来了解有关测试和编码标准的所有信息。

一个真诚的免责声明

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

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

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

路线图

  • 当前的开发和主分支包含 Riak 2.0 版本的功能支持
  • Riak 2.1 功能的开发正在进行中,预计将在 2015 年第二季度完成

许可证和作者

活跃

原始

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