npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

riak-pb

v0.1.9

Published

Riak Protocol Buffers Client

Downloads

6

Readme

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 = require('riak-pb');

Create Client

var client = riak();

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 = riak(options);

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.put({
    bucket: 'test',
    key: 'test',
    content: { 
      value: '{"test":"data"}',
      content_type: 'application/json',
      indexes: [{ key: 'test_bin', value: 'test' }] 
    } 
  },
  function (err, reply) {
    //...
    console.warn("ERr: "+JSON.stringify(err)+" Reply: "+JSON.stringify(reply));
  });

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.put(options, function(err, reply) {
    //...
  });

With vector clock:

var options = { bucket: 'test', key: 'test-vclock', content: { value: '{"test":"data"}', content_type: 'application/json' }, return_body: true };
client.put(options, function (err, reply) {
  if (err) throw err;
  var options = { bucket: 'test', key: 'test-vclock', content: { value: '{"test":"data"}', content_type: 'application/json' }, return_body: true };
  options.vclock = reply.vclock;
  client.put(options, function(reply) {
    // ...
  });
});

get(params, callback)

Example:

client.get({ bucket: 'test', key: 'test' }, function (err, reply) {
  t.equal(++cbCount, 1);
  t.notOk(err, err && err.message);
  t.ok(Array.isArray(reply.content));
  t.equal(reply.content.length, 1);
  t.equal(reply.content[0].value, '{"test":"data"}');
  t.end();
});

getIndex(params, callback)

Example:

client.getIndex({
  bucket: 'test',
  index: 'test_bin',
  qtype: 0,
  key: 'test' },
  function (err, reply) {
    //...
  });

Range query example:

client.getIndex({
  bucket: 'test',
  index: 'test_bin',
  qtype: 1,
  range_min: 'abc',
  range_max: 'abcdef' },
  function (err, reply) {
    //...
  });

setBucket(params, callback)

Example:

client.setBucket('test', { allow_mult: true, n_val: 3 },
  function (err, reply) {
    /// ...
  });

getKeys(bucket[, callback])

With callback:

client.getKeys('test', function (err, keys) {
  /// ...
});

Streaming:

var s = client.getKeys('test');

s.on('readable', function() {
  var key;
  while(key = s.read()) {
    console.log('got key:', key);
  }
});

search(params[, callback])

With callback:

client.search({ index: 'key1_bin', q: 'test' }, function (err, reply) {
  /// ...
});

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.stringify(request), content_type: 'application/json' };

client.mapred(params, function (err, responses) {
  /// ...
});

Streaming:

var request = {
  inputs: 'test',
  query: [
    {
      map: {
        source: 'function (v) { return [[v.bucket, v.key]]; }',
        language: 'javascript',
        keep: true
      }
    }]};

var params = { request: JSON.stringify(request), content_type: 'application/json' };

var s = client.mapred(params);

s.on('readable', function() {
  var res;
  while(res = s.read()) {
    console.log('got res:', res);
  }
});

del(bucket, id[, callback])

del(bucket, options[, callback])

client.del('test', key, function(err) {
  // ...
});

or, with options:

client.del('test', {key: key, vclock: vclock}, function(err) {
  // ...
});

Disconnect

Queues a disconnect after all the pending requests are complete

client.disconnect();

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.