PHP code example of start2004 / riak-php-client

1. Go to this page and download the library: Download start2004/riak-php-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

start2004 / riak-php-client example snippets


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

abstract class ProtobufMessage
{
    ...
}

// lib classes are ;
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);

// lib classes are ;
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();
javascript
"2004/riak-php-client": "3.*"
}