ssdb nodejs client library, ssdb is a fast nosql database, an alternative to redis.
Latest version: v0.0.8
Feel free to open an issue! =_-
- ssdb 1.6.8.8+
$ npm install ssdb
The traditional Node.js way:
var ssdb = require('ssdb');
var client = ssdb.createClient();
client.set('key', 'val', function(err, data){
if (!err) {
console.log(data);
} else throw err;
});
Work with TJ's co:
var co = require('co');
client.thunkify();
co(function *(){
try{
var key = 'key';
var a = yield client.set(key, 'val');
var b = yield client.get(key);
console.log(a, b); // 1 'val'
} catch(e){
throw e;
}
})();
Work with promises:
client.promisify()
client.set('key', 'val')
.then(function(){
return client.get('key')
}).then(function(d){
console.log(d); // 'val'
});
Callback functions have two parameters: error, data
;
- on
status_ok
: onlyerror
isundefined
; - on
status_not_found
:error
anddata
are bothundefined
- on
status_client_error
and othernot_ok
status: onlydata
isundefined
.
To make a ssdb client:
var ssdb = require('ssdb');
var client = ssdb.createClient();
options (with default values):
{
host: '0.0.0.0',
port: 8888,
timeout: 0
}
Quit from ssdb server.
Equivalent to client.conn.sock.unref()
, see http://nodejs.org/api/net.html#net_server_unref.
ssdb.commands // js object keys
- parameters:
cmd
,data
Listener example:
var util = require('util');
client.on('status_ok', function(cmd, data){
console.log(util.format('%s replies ok, data: %s', cmd, data));
});
- parameters:
cmd
- parameters:
cmd
- parameters:
status
,cmd
All events (except 'data
) on nodejs's net.event.connect
are avaliable (reference: http://nodejs.org/api/net.html)
- event 'connect'
- event 'end'
- event 'timeout'
- event 'drain'
- event 'error'
- event 'close'
client.on('error', function(err){
log.error('ssdb connect error: %s', err);
});
Detail docs for ssdb interfaces can be found at: https://github.com/hit9/ssdb.api.docs
Copyright (c) 2014 Eleme, Inc. detail see LICENSE-MIT