GitXplorerGitXplorer
o

zk

public
3 stars
1 forks
0 issues

Commits

List of commits on branch master.
Unverified
03584ce5cb4acce1f11f6ec37e8c5e19ea121ab5

Drop it

ooleksiyk committed 6 years ago
Unverified
ee5cc0f35a0aff76c4d50b6932ccd8a8989e19eb

1.1.1

ooleksiyk committed 6 years ago
Unverified
a8141897ce22c525efebd9c85f78b43c62c1a1f0

Avoid using relative paths

ooleksiyk committed 6 years ago
Unverified
7ed0abd14a61bef26cbdfcbdea7d54c9bef37737

1.1.0

ooleksiyk committed 6 years ago
Unverified
3040981f4a8a77a14667b97c05716dad80253713

Use own copy of node-zookeeper

ooleksiyk committed 6 years ago
Unverified
a76d9d439bec75a6d7fb006bd28b8b4cc4200200

1.0.3

ooleksiyk committed 9 years ago

README

The README file for this repository.

Zk

Build Status david Dependencies david Dev Dependencies license

Zk is a promised based Zookeeper client library for Node. It uses the fork of C binding from node-zookeeper and makes it easier to use.

The following methods are implemented:

  • get
  • set
  • create
  • exists
  • delete
  • getChildren
  • getChildren2

Install

$ npm install zk

Connection

var Zookeeper = require('zk')
var zk = new Zookeeper()

zk.connect().then(function() {
    // zk.create(), zk.set()...
})

Basics

zk.create('/test-node-', 'value', Zookeeper.ZOO_SEQUENCE | Zookeeper.ZOO_EPHEMERAL).then(function(_path) {
    // _path is created node path
})
return zk.set(path, 'value2', -1).then(function(){
    zk.get(path).then(function(reply){
        // reply.stat is node stat object
        // reply.data is node value (Buffer) -> reply.data.toString() will be 'value2'
    })
})

Watches

Watches are implemented as promises conditionaly returned with results:

get without watch:

zk.get(path).then(function(reply) {
    // reply.stat is node stats
    // reply.data is node value (buffer)
})

get with watch:

return zk.get(path, true).then(function(reply) {
    // reply.stat, reply.data as above
    // reply.watch is a promise
    return reply.watch.then(function(event){
        // event.type: 'child' | 'changed' | 'deleted' ..
        // event.state
        // event.path
    })
})

See tests for more

Locks

var Zookeeper = require('zk')
var Lock = Zookeeper.Lock
var zk = new Zookeeper()

// zk.connect() ...

var lock = new Lock(zk, 'lockName')

var promise = lock.lock(function(){
    // we got the lock!
    // ... do something and return a promise
})

Function passed to lock() should return a promise. That promise will be the return value of lock() call