Skip to content

Latest commit

 

History

History
97 lines (80 loc) · 3.38 KB

apiref_udf.md

File metadata and controls

97 lines (80 loc) · 3.38 KB

UDF Methods

public int Aerospike::register ( string $path, string $module [, int $language = Aerospike::UDF_TYPE_LUA  [, array $options ]] )
public int Aerospike::deregister ( string $module [, array $options ])
public int Aerospike::listRegistered ( array &$modules [, int $language  [, array $options ]] )
public int Aerospike::getRegistered ( string $module, string &$code [, int $language = Aerospike::UDF_TYPE_LUA [, array $options ]] )
public int Aerospike::apply ( array $key, string $module, string $function[, array $args [, mixed &$returned [, array $options]]] )
public int Aerospike::scanApply ( string $ns, string $set, string $module, string $function, array $args, int &$scan_id [, array $options ] )
public int Aerospike::queryApply ( string $ns, string $set, array $where, string $module, string $function, array $args, int &$job_id [, array $options ] )
public int Aerospike::jobInfo ( integer $job_id, array &$info [, array $options ] )

Aerospike::scanInfo (deprecated)

public int Aerospike::scanInfo ( integer $scan_id, array &$info [, array $options ] )
public int Aerospike::aggregate ( string $ns, string $set, array $where, string $module, string $function, array $args, mixed &$returned [, array $options ] )

Example

<?php

$config = ["hosts" => [["addr"=>"localhost", "port"=>3000]], "shm"=>[]];
$client = new Aerospike($config, true);
if (!$client->isConnected()) {
   echo "Aerospike failed to connect[{$client->errorno()}]: {$client->error()}\n";
   exit(1);
}

$key = ["ns" => "test", "set" => "users", "key" => 1234];
$bins = ["email" => "[email protected]", "name" => "Hey There"];
// attempt to 'CREATE' a new record at the specified key
$status = $client->put($key, $bins, 0, [Aerospike::OPT_POLICY_EXISTS => Aerospike::POLICY_EXISTS_CREATE]);
if ($status == Aerospike::OK) {
    echo "Record written.\n";
} elseif ($status == Aerospike::ERR_RECORD_EXISTS) {
    echo "The Aerospike server already has a record with the given key.\n";
} else {
    echo "[{$client->errorno()}] ".$client->error();
}

// apply a UDF to a record
$status = $client->apply($key, 'my_udf', 'startswith', ['email', 'hey@'], $returned);
if ($status == Aerospike::OK) {
    if ($returned) {
        echo "The email of the user with key {$key['key']} starts with 'hey@'.\n";
    } else {
        echo "The email of the user with key {$key['key']} does not start with 'hey@'.\n";
    }
} elseif ($status == Aerospike::ERR_UDF_NOT_FOUND) {
    echo "The UDF module my_udf.lua was not registered with the Aerospike DB.\n";
}

// filtering for specific keys
$status = $client->get($key, $record, ["email"], Aerospike::POLICY_RETRY_ONCE);
if ($status == Aerospike::OK) {
    echo "The email for this user is ". $record['bins']['email']. "\n";
    echo "The name bin should be filtered out: ".var_export(is_null($record['bins']['name']), true). "\n";
}
?>