简介
概述
Aerospike C客户端,可用来创建用于存储和读取Aerospike集群数据的应用。C客户端是个智能客户端(smart client),周期性从集群中各节点上获取集群的当前状态,并且管理客户端与集群间的交互。
Aerospike C客户使用同步的请求-响应模型。 基于libevent2事件驱动的C客户端是另外一个单独的实现,请参阅“Aerospike Libevent2客户端“。
支持的平台
Aerospike C客户端目前可用于下面的64位平台:
- Mac OS X
- Linux
Aerospike为以下平台提供经认证的安装包:
- Mac OS X 10.8
- CentOS/Redhat 6
- Debian 6, 7
- Ubuntu 12.04
认证的安装包可于此外下载: http://www.aerospike.com/download/client/c/latest。
源码可从Github上下载:https://github.com/aerospike/aerospike-client-c。
代码一览
下面给出的代码片断,示意向Aerospike服务器写入一条记录的主要步骤:
as_error err;
as_config config;
as_config_init(&config);
config.hosts[0] = { .addr = "127.0.0.1", .port = 3000 };
aerospike as;
aerospike_init(&as, &config);
aerospike_connect(&as, &err);
as_key key;
as_key_init(&key, "test", "demo_set", "test_key");
as_record rec;
as_record_inita(&rec, 2);
as_record_set_int64(&rec, "test-bin-1", 1234);
as_record_set_str(&rec, "test-bin-2", "test-bin-2-data");
aerospike_key_put(&as, &err, NULL, &key, &rec);
aerospike_close(&as);
aerospike_destroy(&as);