php和aerospike-设置数据时出错
作者:互联网
我在ubuntu上使用了Aerospike.
我能够在命令行上从Aerospike上设置和获取记录.
在PHP中,我可以实例化AeroSpike类,但是当我尝试向其中添加一些数据时,它显示为“ AEROSPIKE_ERR_NAMESPACE_NOT_FOUND”.
令人惊讶的是,错误代码为20,根据文档,错误代码应为501. api中没有定义此类错误代码20.
https://github.com/aerospike/aerospike-client-nodejs/blob/master/docs/status.md
我尝试过的代码.
<?php
ini_set( 'display_errors', 1 );
ini_set( 'error_reporting', E_ALL );
// set the records to never expire unless specified otherwise
define( 'RECORD_TIME_TO_LIVE', 0 );
$config = array(
"hosts" => array(
array( "addr" => "127.0.0.1", "port" => 3000 )
)
);
$db = new Aerospike( $config );
// failure check
if ( !$db->isConnected() ) {
echo "Failed to connect to the Aerospike server [{$db->errorno()}]: {$db->error()}\n";
exit( 1 );
}
$key = $db->initKey("infosphere", "characters", 1);
$put_vals = array("name" => "Scruffy", "Occupation" => "The Janitor");
$status = $db->put($key, $put_vals, RECORD_TIME_TO_LIVE);
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 "[{$db->errorno()}] :".$db->error();
}
$db->close();
?>
欢迎任何帮助.
谢谢,
解决方法:
Aerospike服务器配置中是否定义了名称空间“ infosphere”?
https://www.aerospike.com/docs/operations/configure/namespace/
存在的默认名称空间仅是test和bar.必须定义其他任何其他名称空间,并重新启动Aerospike服务器,以使新名称空间正常工作.
我将检查错误代码.
标签:aerospike,php 来源: https://codeday.me/bug/20191028/1954101.html