riak-pb
Riak Protocol Buffer Client for Node.js.
Features:
- streaming
- fail-over
- automatic retry
- connection pooling
- load balancing
Install
Include riak-pb
in your dependency list or install:
$ npm install riak-pb
Use
Require
var riak = ;
Create Client
var client = ;
Or, with options:
var options = nodes: host: 'myriakhostname.acme.com' port: 8087 maxPool: 5 // Maximum number of connections in the connection pool - default is 5 maxRetries: 10 // maximum times the client tries to reconnect before failing - default is 10 maxDelay: 2000 // maximum time (ms) between reconnections - reconnections have an exponential backoff, but limited to this value - default is 2000; var client = ;
Access Riak
The API is based on the Riak Protocol spec, check it out to find out about what arguments you need.
put(params, callback)
Examples:
client;
With multiple indexes:
var indexes = key: 'key1_bin' value: 'value1' key: 'key2_bin' value: 'value2' ; var options = bucket: 'test' key: 'test-put-index' content: value: '{"test":"data"}' content_type: 'application/json' indexes: indexes return_body: true ; client;
With vector clock:
var options = bucket: 'test' key: 'test-vclock' content: value: '{"test":"data"}' content_type: 'application/json' return_body: true ;client;
get(params, callback)
Example:
client;
getIndex(params, callback)
Example:
client;
Range query example:
client;
setBucket(params, callback)
Example:
client;
getKeys(bucket[, callback])
With callback:
client;
Streaming:
var s = client; s;
search(params[, callback])
With callback:
client;
mapred(params[, callback])
With callback:
var request = inputs: 'test' query: map: source: 'function (v) { return [[v.bucket, v.key]]; }' language: 'javascript' keep: true ; var params = request: JSON content_type: 'application/json' ; client;
Streaming:
var request = inputs: 'test' query: map: source: 'function (v) { return [[v.bucket, v.key]]; }' language: 'javascript' keep: true ; var params = request: JSON content_type: 'application/json' ; var s = client; s;
del(bucket, id[, callback])
del(bucket, options[, callback])
client;
or, with options:
client;
Disconnect
Queues a disconnect after all the pending requests are complete
client;
Others
- getBuckets(callback) // callback(err, buckets)
- getBucket(bucket[, callback]) // callback(err, bucketInfo)
- setBucket(bucket, props[, callback]) // callback(err)
- setClientId (client_id[, callback]) // callback(err)
- getClientId (callback) // callback(err, clientId)
- ping (callback) // callback(err)
- getServerInfo(callback) // callback(err, reply)
Events
The client object emits these events:
- 'error' - (err)
- 'warning' - (warning) - Emitted when there is an internal error, like a disconnection. In this case, the client will transparently attempt to reconnect (up to a limit of attempts) and a "warning" will be emitted with the underlying error object.