我想知道如何使用 C++
客户端在 ZooKeeper
中创建持久节点。我从documentation知道, 有一个方法zoo_acreate
。文档对这种方法说:
This method will create a node in ZooKeeper. A node can only be created if it does not already exists. The Create Flags affect the creation of nodes. If ZOO_EPHEMERAL flag is set, the node will automatically get removed if the client session goes away. If the ZOO_SEQUENCE flag is set, a unique monotonically increasing sequence number is appended to the path name.
但是,不幸的是,几乎与 C++ 库一样,这个库完全缺乏合理的小示例来演示库方法的用法。例如,在这种情况下,文档页面是关于 zoo_acreate
方法的,但是一些看起来很糟糕的示例完全是关于其他东西的(它甚至没有提到 zoo_acreate
方法)。
所以,我的问题是如何设置这些标志 ZOO_EPHEMERAL
和 ZOO_SEQUENCE
。很高兴在一些小例子的背景下看到这一点。谢谢!
最佳答案
谷歌搜索“zoo_acreate ZOO_EPHEMERAL”给出了第七个结果:
string path = "/nodes/";
string value = "data";
int rc = zoo_acreate(zh, path.c_str(), value.c_str(), value.length(),
&ZOO_OPEN_ACL_UNSAFE, ZOO_EPHEMERAL | ZOO_SEQUENCE, &czoo_created, &where);
关于c++ - ZooKeeper 中的持久节点和临时节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32665881/