【问题标题】:php and aerospike - error in setting dataphp和aerospike - 设置数据错误
【发布时间】:2015-02-16 12:14:28
【问题描述】:

我在 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();
?>

欢迎任何帮助。

谢谢,

【问题讨论】:

    标签: php aerospike


    【解决方案1】:

    命名空间“infosphere”是否在您的 Aerospike 服务器配置中定义?

    https://www.aerospike.com/docs/operations/configure/namespace/

    存在的默认命名空间只有 test 和 bar。必须定义任何其他额外的命名空间并重新启动 Aerospike 服务器以使新命名空间正常工作。

    我会检查错误代码。

    【讨论】:

    • 是的,经过大量搜索后才知道 :) 感谢您的确认。
    猜你喜欢
    • 2022-11-24
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2017-07-24
    • 2016-01-02
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    相关资源
    最近更新 更多