Skip to content
Visit booth 3171 at Google Cloud Next to see how to unlock real-time decisions at scaleMore info

Batched commands

The following example code peforms a batched command.

<?php
namespace Aerospike;
$namespace = "test";
$set = "test";
$socket = "/tmp/asld_grpc.sock";
// Create the client connection
$client = Client::connect($socket);
echo "* Connected to the local daemon: $client->hosts \n";
// Define a key with a namespace, set name, and user-defined key
$key = new Key($namespace, $set, 1);
$wp = new WritePolicy();
// Create a new record
$client->put($wp, $key, [new Bin("bini", 1), new Bin("bins", "b"), new Bin("bin1", [1, 2, 3, 4])]);
// Set up the batch operation
$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);
// Execute the batch operation
$bp = new BatchPolicy();
$recs = $client->batch($bp, [$bw, $br, $bd]);
var_dump($recs);
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?