多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 數據庫 > 數據庫應用 > [置頂] Aerospike數據庫實戰(五) -- Aerospike C Client 開發

[置頂] Aerospike數據庫實戰(五) -- Aerospike C Client 開發

來源:程序員人生   發布時間:2017-03-08 08:25:29 閱讀次數:7573次

本人原創文章,轉載請注明出處:http://blog.csdn.net/yanshu2012/article/details/54288856

1. C Client 安裝

sudo yum install openssl-devel
sudo yum install gcc gcc-c++
wget -S "http://www.aerospike.com/artifacts/aerospike-client-c/3.1.18/aerospike-client-c⑶.1.18.el6.x86_64.tgz" 
tar -zxvf aerospike-client-c⑶.1.18.el6.x86_64.tgz 
sudo rpm -i aerospike-client-c-devel⑶.1.18⑴.el6.x86_64.rpm
Edit

2. 程序Makefile修改

  • 增加靜態庫援用: /usr/lib/libaerospike.a
  • 增加動態庫援用: -lssl -lcrypto -lrt -ldl -lpthread -pthread
  • 增加頭文件援用: /usr/include/aerospike
Edit

3. key-Value Store API 開發代碼實例

3.1 Write Records

#include <errno.h>
#include <getopt.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <iostream>
#include <aerospike/aerospike.h>
#include <aerospike/aerospike_key.h>
#include <aerospike/aerospike_udf.h>
#include <aerospike/as_arraylist.h>
#include <aerospike/as_bin.h>
#include <aerospike/as_bytes.h>
#include <aerospike/as_error.h>
#include <aerospike/as_config.h>
#include <aerospike/as_key.h>
#include <aerospike/as_list.h>
#include <aerospike/as_record.h>
#include <aerospike/as_record_iterator.h>
#include <aerospike/as_status.h>
#include <aerospike/as_val.h>

using namespace std;

int main(int argc, char* argv[])
{
    as_config config;
    as_config_init(&config);
    config.conn_timeout_ms = 100;
    as_config_add_host(&config,"127.0.0.1",3000);
    aerospike as;
    aerospike_init(&as, &config);
    as_error err;
    if (aerospike_connect(&as, &err) != AEROSPIKE_OK) {
       fprintf(stderr, "err(%d) %s at [%s:%d]\n", err.code, err.message, err.file, err.line);
    }

    as_record rec;
    as_record_inita(&rec, 2);
    as_record_set_str(&rec, "test-bin⑴", "1234");
    as_record_set_str(&rec, "test-bin⑵", "test-bin⑵-data");

    as_key key;
    as_key_init_str(&key, "cm", "test-set", "test-key");

    if (aerospike_key_put(&as, &err, NULL, &key, &rec) != AEROSPIKE_OK) {
       fprintf(stderr, "err(%d) %s at [%s:%d]\n", err.code, err.message, err.file, err.line);
     }  

    as_record_destroy(&rec);

    if (aerospike_close(&as, &err) != AEROSPIKE_OK) {
        fprintf(stderr, "err(%d) %s at [%s:%d]\n", err.code, err.message, err.file, err.line);
    }
    aerospike_destroy(&as);
}


3.2 Read Records
#include <errno.h>
#include <getopt.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <iostream>
#include <aerospike/aerospike.h>
#include <aerospike/aerospike_key.h>
#include <aerospike/aerospike_udf.h>
#include <aerospike/as_arraylist.h>
#include <aerospike/as_bin.h>
#include <aerospike/as_bytes.h>
#include <aerospike/as_error.h>
#include <aerospike/as_config.h>
#include <aerospike/as_key.h>
#include <aerospike/as_list.h>
#include <aerospike/as_record.h>
#include <aerospike/as_record_iterator.h>
#include <aerospike/as_status.h>
#include <aerospike/as_val.h>

using namespace std;

int main(int argc, char* argv[])
{
    as_config config_get;
    as_config_init(&config_get);
    config_get.conn_timeout_ms = 100;
    as_config_add_host(&config_get,"210.73.210.142",3000);
    aerospike as_get;
    aerospike_init(&as_get, &config_get);
    as_error err_get;
    if (aerospike_connect(&as_get, &err_get) != AEROSPIKE_OK) {
       fprintf(stderr, "err(%d) %s at [%s:%d]\n", err_get.code, err_get.message, err_get.file, err_get.line);
    }

    as_record* rec_get;

    as_key key_get;
    as_key_init_str(&key_get, "cm", "test-set", "test-key");

   static const char* bins_1_3[] = { "test-bin⑴", "test-bin⑵", NULL };

   if (aerospike_key_select(&as_get, &err_get, NULL, &key_get, bins_1_3, &rec_get) != AEROSPIKE_OK) {
      fprintf(stderr, "err(%d) %s at [%s:%d]\n", err_get.code, err_get.message, err_get.file, err_get.line);
    }
    // counter for the bins
    int i = 0;

    // iterator over bins
    as_record_iterator it;
    as_record_iterator_init(&it, rec_get);

    while (as_record_iterator_has_next(&it)) {
    // we expect the bins to contain a list of [action,timestamp]

        as_bin     *bin         = as_record_iterator_next(&it);
        char     *bin_name     = as_bin_get_name(bin);
        as_val * value =  (as_val*)as_bin_get_value(bin);
        as_string * str_value     = as_string_fromval(value);

        if (str_value) {
            char * v= as_string_get(str_value);
            cout << " bin[" << i << "] name=" << bin_name << " value=" << v << "\n";
            free(v);
        }
        else {
            cout << "Error: bin[" << i << "] name=" << bin_name << " has unexpected type " << as_bin_get_type(bin) << "\n";
        }

        i++;
     }

    // release the iterator
    as_record_iterator_destroy(&it);

    //as_record_destroy(rec_get);

    if (aerospike_close(&as_get, &err_get) != AEROSPIKE_OK) {
        fprintf(stderr, "err(%d) %s at [%s:%d]\n", err_get.code, err_get.message, err_get.file, err_get.line);
    }     
    aerospike_destroy(&as_get);

}
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 最近韩国动漫hd免费观看 | 国产亚洲精品国产 | 国产女人18一级毛片视频 | 欧美偷窥自拍 | 亚洲精品成人a在线观看 | 国产欧美另类 | 久久久精品国产免费观看同学 | 成人永久福利在线观看不卡 | 欧美 自拍偷拍 | 黄色免费观看网址 | 久久做 | 亚洲爱爱久久精品 | 国产精品久久久久久久午夜片 | 国产激情在线观看完整流畅 | 精品国产一区二区三区在线 | 国产精品免费久久久久影院小说 | 在线观看一区二区三区视频 | 亚洲永久精品免费www52zcm男男 | 欧美黄色片免费观看 | 视频在线观看免费 | 欧美日韩中文国产一区二区三区 | 国产精品久久久久国产精品三级 | 性8sex亚洲区入口 | 中文字幕免费看 | 黄色xxxxx| 国产美女无遮挡免费视频 | 国产毛片毛片精品天天看 | 国产日韩欧美一区二区三区视频 | 国产精品成人久久久 | 欧美日韩大尺码免费专区 | 91se在线看片国产免费观看 | 国产高清一区二区三区 | 日产一一到六区网站免费 | 那一个欧美一级毛片 | 国产欧美日韩中文久久 | 2020国产精品| 色欧美亚洲 | 亚洲14p| 精品哟哟哟国产在线观看不卡 | 国产精品va在线观看手机版 | 午夜免费福利 |