PHP code example of aerospike / aerospike-php
1. Go to this page and download the library: Download aerospike/aerospike-php 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/ */
aerospike / aerospike-php example snippets
$socket = "/tmp/asld_grpc.sock";
$client = Client::connect($socket);
// Instantiate the WritePolicy object
$writePolicy = new WritePolicy();
$writePolicy->setRecordExistsAction(RecordExistsAction::Update);
$writePolicy->setGenerationPolicy(GenerationPolicy::ExpectGenEqual);
$writePolicy->setExpiration(Expiration::seconds(3600)); // Expiring in 1 hour
$writePolicy->setMaxRetries(3);
$writePolicy->setSocketTimeout(5000);
namespace Aerospike;
try{
$socket = "/tmp/asld_grpc.sock";
$client = Client::connect($socket);
var_dump($client->socket);
}catch(AerospikeException $e){
var_dump($e);
}
$key = new Key("namespace", "set_name", 1);
//PUT on differnet types of values
$wp = new WritePolicy();
$bin1 = new Bin("bin1", 111);
$bin2 = new Bin("bin2", "string");
$bin3 = new Bin("bin3", 333.333);
$bin4 = new Bin("bin4", [
"str",
1984,
333.333,
[1, "string", 5.1],
[
"integer" => 1984,
"float" => 333.333,
"list" => [1, "string", 5.1]
]
]);
$bin5 = new Bin("bin5", [
"integer" => 1984,
"float" => 333.333,
"list" => [1, "string", 5.1],
null => [
"integer" => 1984,
"float" => 333.333,
"list" => [1, "string", 5.1]
],
"" => [ 1, 2, 3 ],
]);
$client->put($wp, $key, [$bin1, $bin2, $bin3, $bin4, $bin5]);
//GET
$rp = new ReadPolicy();
$record = $client->get($rp, $key);
var_dump($record->bins);
//UPDATE
$client->prepend($wp, $key, [new Bin("bin2", "prefix_")]);
$client->append($wp, $key, [new Bin("bin2", "_suffix")]);
//DELETE
$deleted = $client->delete($wp, $key);
var_dump($deleted);
$client->close()
namespace Aerospike;
$namespace = "test";
$set = "test";
$socket = "/tmp/asld_grpc.sock";
$client = Client::connect($socket);
echo "* Connected to the local daemon: $client->hosts \n";
$key = new Key($namespace, $set, 1);
$wp = new WritePolicy();
$client->put($wp, $key, [new Bin("bini", 1), new Bin("bins", "b"), new Bin("bin1", [1, 2, 3, 4])]);
$bwp = new BatchWritePolicy();
$exp = Expression::lt(Expression::intBin("bin1"), Expression::intVal(1));
$batchWritePolicy->setFilterExpression($exp);
$ops = [Operation::put(new Bin("put_op", "put_val"))];
$bw = new BatchWrite($bwp, $key, $ops);
$brp = new BatchReadPolicy();
$br = new BatchRead($brp, $key, []);
$bdp = new BatchDeletePolicy();
$bd = new BatchDelete($bdp, $key);
$bp = new BatchPolicy();
$recs = $client->batch($bp, [$bw, $br, $bd]);
var_dump($recs);
bash https://github.com/aerospike/php-client.git
cd php-client
bash
cd php-client/aerospike-connection-manager
bash
php -v
bash
cd php-client
sudo make
bash
cd php-client
cargo clean && cargo build --release