A node.js client driver for Doozer
Doozer.js requires the pbuf
Protocol Buffers module, which requires protobuf to be installed in /usr/local
Add doozer
to your package.json
{
"dependencies": {
"doozer": "~0.1"
}
}
Then:
var Doozer = require('doozer')
Connect to a Doozerd server on the given host and port. Returns a Doozer connection object.
Arguments
- port - server port number to connect to.
- host - server host to connect to. Either an IP string or host name
- callback() - An optional callback for the 'connect' event.
Example
Doozer.dial(8046, "localhost", function () {
console.log("connected to Doozer")
});
Same as above except address is a string like "localhost:8047"
. If no port is given 8046 will be assumed.
Connect to a Doozer cluster using a doozer:?
uri string, optionally using DzNS for node lookup. See Doozer URIs for details
Note, this function DOES NOT return a Doozer object. It is available as this
in the callback.
Arguments
- uri - a "doozer:?" uri with either
ca
orcn
parameters. - buri - an optional "doozer:?" uri to the DzNS server
- callback(err) - A required callback for the 'connect' event.
Example
Doozer.dialUri("doozer:?cn=local", "doozer:?ca=10.0.1.5:8048", function (err) {
this.rev(function(err, rev) {
console.log(rev)
})
})
Return the current rev number
Arguments
- callback(err, rev) - returns the rev number on success
Sets a value for the given file
Arguments
- path - path to the file to set
- oldRev - rev number this path had before
- value - the value to set
- callback(err, rev) - returns the new rev number on success
Get the value at the given path
Arguments
- path - path to the file
- rev - optional rev number of the value to get. Defaults to newest rev
- callback(err, value, rev) - returns the value and rev number on success
Delete the given path with the given rev number
Arguments
- path - the path to delete
- rev - the rev to delete
- callback(err, response)
Gets the names of the children of the given dir
Arguments
- dir - the path to a directory (must not be a file)
- offset - skips this number of child records, should usually be 0
- limit - max number of child names to return, use -1 for no limit
- rev - optional rev number
- callback(err, names) - returns an array of child node names on success
Like getDir
except returns an array of StatInfo
instead of names
Returns the file length and rev number at the given path
Arguments
- path - path to a file
- rev - optional rev number
- callback(err, length, rev) - returns the length and rev on success
Return an object with stat information on the given path. A StatInfo contains:
- len
- rev
- name
- isSet
- isDir
Arguments
- path - path to a file or directory
- rev - optional rev number
- callback(err, statInfo) - returns a statInfo object on success
Registers the given callback to be called when a file covered by glob meets or exceeds the given rev.
Arguments
- glob - a path pattern to watch. see Glob Notation
- rev - the rev to watch for
- callback(err, response)
Closes the connection to Doozer