$db = new Aerospike($config, false); if (!$db->isConnected()) { echo fail("Could not connect to host {$HOST_ADDR}:{$HOST_PORT} [{$db->errorno()}]: {$db->error()}"); exit(1); } echo success(); if (isset($args['a']) || isset($args['annotate'])) { display_code(__FILE__, $start, __LINE__); } echo colorize("Registering the UDF module ≻", 'black', true); $start = __LINE__; $copied = copy(__DIR__ . '/lua/example_aggregate_udf.lua', ini_get('aerospike.udf.lua_user_path') . '/example_aggregate_udf.lua'); if (!$copied) { echo fail("Could not copy the local lua/example_aggregate_udf.lua to " . ini_get('aerospike.udf.lua_user_path')); } $status = $db->register(ini_get('aerospike.udf.lua_user_path') . '/example_aggregate_udf.lua', "example_aggregate_udf.lua"); if ($status == Aerospike::OK) { echo success(); } elseif ($status == Aerospike::ERR_UDF_NOT_FOUND) { echo fail("Could not find the udf file " . ini_get('aerospike.udf.lua_user_path') . '/example_aggregate_udf.lua'); } else { echo standard_fail($db); } if (isset($args['a']) || isset($args['annotate'])) { display_code(__FILE__, $start, __LINE__); } // display the Lua code of the UDF module $lua = file_get_contents(ini_get('aerospike.udf.lua_user_path') . '/example_aggregate_udf.lua'); echo colorize($lua, 'purple', false); echo colorize("Creating a secondary index on the 'age' bin of test.characters ≻", 'black', true); $start = __LINE__;
$status = $db->scan("test", "demo", function ($record) { var_dump($record); return true; }, array(Aerospike::OPT_SCAN_CONCURRENTLY => true)); var_dump($db->error()); if ($status != Aerospike::OK) { echo "Scan Failed"; } $db->close(); } else { echo "Aerospike DB connection is not established"; } }); $app->get('/scanApply', function () use($db, $LUA_DIR) { if ($db->isConnected()) { $status = $db->register($LUA_DIR . "/test_record_udf.lua", "test_record_udf.lua"); if ($status != Aerospike::OK) { echo "UDF register failed\n"; $db->close(); exit(0); } $status = $db->scanApply("test", "demo", "test_record_udf", "bin_udf_operation_integer", array('age', 1, 2), $scan_id); if ($status != Aerospike::OK) { echo "Scan Apply Failed"; break; } $status = $db->scanInfo($scan_id, $scan_info); if ($status != Aerospike::OK) { echo "Scan Info Failed"; break; }