- Notifications
You must be signed in to change notification settings - Fork47
Lua binding of apache zookeeper.
License
Apache-2.0, BSD-3-Clause licenses found
Licenses found
forhappy/zklua
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Zklua is the first(as far as I know) lua binding of apache zookeeper. If you are wondering what is apache zookeeper, please visit thezookeeper official website to get more information about it, hereinafter is an one-sentence description that can inform of you what is apache zookeeper:
ZooKeeper is a high-performance coordination service for distributed applications. It exposes common services - such as naming, configuration management, synchronization, and group services - in a simple interface so you don't have to write them from scratch. You can use it off-the-shelf to implement consensus, group management, leader election, and presence protocols.
Zklua provides a complete API binding of Lua for apache zookeeper(hereinafter referred to aszookeeper
), including synchronous and asynchronous interface as well as some useful auxiliary APIs. That is, you may create/delete/get/update(CRUD) a zookeeper node(ZNode) in lua language synchronously and/or asynchronously without any pains.
First of all, you have to get zklua source code from github:
$ git clone git@github.com:forhappy/zklua.git
Zklua has no other dependencies except for zookeeper c API implementation, which usually resides inzookeeper-X.Y.Z/src/c
, hence you need to install zookeeper c API at first.
all you have to do is just amake
to compile zklua:
$ make
If you want to install zklua into your system after you have compiled zklua, you need tomake install
(as root):
$ make install
Deleting a ZNode.
Here is a tiny lua example to show you deleting a ZNode from zookeeper server.
require"zklua"functionzklua_my_watcher(zh,type,state,path,watcherctx)iftype==zklua.ZOO_SESSION_EVENTthenifstate==zklua.ZOO_CONNECTED_STATEthenprint("Connected to zookeeper service successfully!\n");elseif (state==ZOO_EXPIRED_SESSION_STATE)thenprint("Zookeeper session expired!\n");endendendfunctionzklua_my_void_completion(rc,data)print("zklua_my_void_completion:\n")print("rc:"..rc.."\tdata:"..data)endzklua.set_log_stream("zklua.log")zh=zklua.init("127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183",zklua_my_watcher,10000)ret=zklua.adelete(zh,"/zklua",-1,zklua_my_void_completion,"zklua adelete.")print("zklua.adelete ret:"..ret)print("hit any key to continue...")io.read()
Set watch on a specified path.
Here is a tiny lua example to show you set a watch on a specified path.
require"zklua"functionzklua_my_global_watcher(zh,type,state,path,watcherctx)iftype==zklua.ZOO_SESSION_EVENTthenifstate==zklua.ZOO_CONNECTED_STATEthenprint("Connected to zookeeper service successfully!\n");elseif (state==ZOO_EXPIRED_SESSION_STATE)thenprint("Zookeeper session expired!\n");endendendfunctionzklua_my_local_watcher(zh,type,state,path,watcherctx)print("zklua_my_local_watcher(".."type:"..type..", state:"..state..", path:"..path..")")print("zklua_my_local_watcher(".."watcherctx:"..watcherctx..")")endfunctionzklua_my_stat_completion(rc,stat,data)print("zklua_my_stat_completion:\n")print("rc:"..rc.."\tdata:"..data)endzklua.set_log_stream("zklua.log")zh=zklua.init("127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183",zklua_my_global_watcher,10000)ret=zklua.awexists(zh,"/zklua",zklua_my_local_watcher,"zklua_my_local_watcher",zklua_my_stat_completion,"zklua aexists.")print("zklua.aexists ret:"..ret)print("hit any key to continue...")io.read()
Seedocs/zklua.lua for more details about zklua's API specification.
Licensed to the Apache Software Foundation (ASF) under oneor more contributor license agreements. See the NOTICE filedistributed with this work for additional informationregarding copyright ownership. The ASF licenses this fileto you under the Apache License, Version 2.0 (the"License"); you may not use this file except in compliancewith the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
About
Lua binding of apache zookeeper.
Resources
License
Apache-2.0, BSD-3-Clause licenses found
Licenses found
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Contributors3
Uh oh!
There was an error while loading.Please reload this page.