Aerospike 无法将列表添加到记录中 我试图向数据库添加一个记录,它有3个容器,其中一个是用我的C++程序(我使用SalpPIKE的C客户端库)的列表,但是在执行我的程序之后,只有2的容器被添加到记录中。由于某些原因,我无法添加具有列表值的第三个bin
以下是程序:Aerospike 无法将列表添加到记录中 我试图向数据库添加一个记录,它有3个容器,其中一个是用我的C++程序(我使用SalpPIKE的C客户端库)的列表,但是在执行我的程序之后,只有2的容器被添加到记录中。由于某些原因,我无法添加具有列表值的第三个bin,aerospike,Aerospike,以下是程序: #include<aerospike/aerospike.h> #include<aerospike/as_arraylist.h> #include <aerospike/as_record.h> #include<aerospike/as_record_iterator.h> #include <aerospike/as_policy.h> #include<aerospike/aerospike_key.h&g
#include<aerospike/aerospike.h>
#include<aerospike/as_arraylist.h>
#include <aerospike/as_record.h>
#include<aerospike/as_record_iterator.h>
#include <aerospike/as_policy.h>
#include<aerospike/aerospike_key.h>
#include<aerospike/as_std.h>
#include<aerospike/as_integer.h>
#include<aerospike/as_string.h>
#include<iostream>
#include<aerospike/as_hashmap.h>
#include<string>
using namespace std;
int main()
{
as_error err;
as_config config;
as_config_init(&config);
config.policies.write.key = AS_POLICY_KEY_SEND;
as_config_add_host(&config, "182.18.182.192", 3000);
aerospike as;
aerospike_init(&as, &config);
if(aerospike_connect(&as, &err)!=AEROSPIKE_OK)
{
printf("error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
}
as_key key;
as_record rec;
as_record_init(&rec, 2);
int n;
cout<<endl<<"Enter the number of records to enter: ";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<endl<<"Enter the name: ";
string pk;
getline(cin>>ws,pk);
as_key_init(&key, "test", "vishal_set", pk.c_str());
cout<<endl<<"Enter the age: ";
int age;
cin>>age;
as_record_set_int64(&rec, "age", age);
cout<<endl<<"Enter the contact no: ";
string contact_no;
getline(cin>>ws,contact_no);
as_record_set_str(&rec, "contact_no", contact_no.c_str());
as_arraylist list;
as_arraylist_inita(&list,2);
as_arraylist_append_str (&list, "playing football");
as_arraylist_append_str (&list, "playing cricket");
cout<<endl<<"Number of elements in the list: "<<as_arraylist_size(&list)<<endl;
if(!(as_record_set_list(&rec, "hobbies", (as_list *)&list)))
{
printf("\n[%s::%d]Error\n",__FILE__,__LINE__);
}
if (aerospike_key_put(&as, &err,NULL, &key, &rec) != AEROSPIKE_OK)
{
printf("error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
}
}
if(aerospike_close(&as,&err)!=AEROSPIKE_OK)
{
printf("error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
}
aerospike_destroy(&as);
return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
作为错误;
as_config config;
as_config_init(&config);
config.policies.write.key=AS\u POLICY\u key\u SEND;
as_config_add_host(&config,“182.18.182.192”,3000);
aerospike as;
aerospike_init(&as,&config);
如果(aerospike\u连接(&as,&err)!=aerospike\u正常)
{
printf(“错误(%d)%s位于[%s:%d]”,err.code,err.message,err.file,err.line);
}
as_键;
as_record rec;
as_record_init(&rec,2);
int n;
幸运的是,我自己找到了我的列表没有被添加到记录中的原因。结果证明这是一个非常愚蠢的错误
原因是我在将初始化为_record
时犯了一个错误。因为我在记录中添加了3个存储箱,所以我应该将其初始化为作为_record\u init(&rec,3);