etcd_client
简介
基于pkg.etcdv3实现的etcd客户端
组件接口
Client.gs
etcd客户端对象
etcd_client.gs
函数原型 | 函数作用 |
---|---|
object new_client(string host, int port = 2379) | 创建一个etcd客户端 |
Watcher.gs
处理监听的对象
函数原型 | 函数作用 |
---|---|
void watch() | 启动监听(创建独立线程) |
样例
public object client()
{
if (_client_ob)
return _client_ob;;
object client_ob = etcd_client.new_client("127.0.0.1");
if (! client_ob)
return nil;
_client_ob = client_ob;
return _client_ob;
}
public void test()
{
function func = (WatchResponse resp) {
printf("WatchResponse: %O\n", resp);
};
function succeed_callback = (WatchResponse resp) {
printf("succeed_callback: %O\n", resp);
};
client().watch( "aaa", "aaa999", func, succeed_callback);
}
public void test1()
{
coroutine.create(nil, () {
//test();
});
coroutine.sleep(1);
string key = "x2";
client().insert(key, 1234);
printf("%s: new value: %M\n", key, _client_ob.get(key));
}
public void test2()
{
bool success;
let success, mixed lease_id = client().lease_grant(1000);
printf("1->success: %M, lease_id: %O\n", success, lease_id);
client().put("aaa", 123, lease_id);
let success, mixed result = client().lease_time_to_live(lease_id);
printf("2->success: %M, result: %O\n", success, result);
}