Official Riak client for PHP

v1.0 2021-07-14 06:38 UTC

This package is auto-updated.

Last update: 2024-11-29 05:51:39 UTC


README

支持 PHP7以上, protobuf修改为 Google 官方protobuf

示例

官方示例,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);

Installation

Dependencies

  • PHP 5.4+
  • PHP Extensions: curl, json and openssl protobuf
  • Riak 2.1+

Riak Client for PHP

Packagist

Riak PHP Client is a library which makes it easy to communicate with Riak, an open source, distributed database that focuses on high availability, horizontal scalability, and predictable latency. This library communicates with Riak's HTTP interface using the cURL extension. If you want to communicate with Riak using the Protocol Buffers interface, use the Official PHP PB Client. Both Riak and this library are maintained by Basho Technologies.

To see other clients available for use with Riak visit our Documentation Site

  1. Riak Client for PHP 修改版
    1. Installation
      1. Dependencies
  2. Riak Client for PHP
    1. Installation
      1. Dependencies
      2. Composer Install
    2. Documentation
      1. Example Usage
    3. Contributing
      1. An honest disclaimer
    4. Roadmap
    5. License and Authors

Installation

Dependencies

Composer Install

This library has been added to Packagist to simplify the installation process. Run the following composer command:

$ composer require "basho/riak": "3.0.*"

Alternately, manually add the following to your composer.json, in the require section:

"require": {
    "basho/riak": "3.0.*"
}

And then run composer update to ensure the module is installed.

Documentation

  • Master: Build Status

A fully traversable version of the API documentation for this library can be found on Github Pages.

Example Usage

Below is a short example of using the client. More substantial sample code is available in examples.

// 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();

Contributing

This repo's maintainers are engineers at Basho and we welcome your contribution to the project! You can start by reviewing CONTRIBUTING.md for information on everything from testing to coding standards.

An honest disclaimer

Due to our obsession with stability and our rich ecosystem of users, community updates on this repo may take a little longer to review.

The most helpful way to contribute is by reporting your experience through issues. Issues may not be updated while we review internally, but they're still incredibly appreciated.

Thank you for being part of the community! We love you for it.

Roadmap

  • Current develop & master branches contain feature support for Riak version 2.1+
  • Add support for Riak TS Q2 2016

License and Authors

Copyright (c) 2015 Basho Technologies, Inc. Licensed under the Apache License, Version 2.0 (the "License"). For more details, see License.