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

aerospike-p

v0.3.4

Published

Aerospike promisified Node.js client

Downloads

7

Readme

aerospike-p

npm version

aerospike-p is a promisified Aerospike Node.js client library. It internally uses the official aerospike (1.0.53) client driver.

var aerospike = require('aerospike-p');

var client = new aerospike.Client({ hosts: [{ addr: '127.0.0.1', port: 3000 }] });

client.connect().then(function() {
    return client.put(aerospike.key('test', 'set1', 'key1'), { field1: 'value1' });
}).then(function() {
    return client.get(aerospike.key('test', 'set1', 'key1'));
}).then(function(res) {
    console.log(res[0]);
    return client.close();
});

Conversion Notes

  • All returned promises resolve when the underlying operation was successful (error.code === AEROSPIKE_OK).
    • If the number of arguments of the original callback function was 1 (error), promisified function resolves to undefined.
    • If the number of arguments of the original callback function was 2 (error, param1), promisified function resolves to the second argument (param1).
    • If the number of arguments of the original callback function was more than 2, promisified function resolves to an array of all arguments except for error.
  • All returned promises reject when the underlying operation was failure (error.code !== AEROSPIKE_OK).
    • Promisified function rejects with the same error object.
  • All Promise objects are implemented using Bluebird. So you can use some Bluebird goodies (e.g. .spread()) if you'd like.
  • aerospike-p is fully compatible with the original aerospike.
    • So you should be able to change require('aerospike') to require('aerospike-p') in your code with no changes. (But, of course, your code is still non-promisified.)

References

Key

You can create a new Key instance by defining a plain object.

var key = { ns: 'ns1', set: 'set1', key: 'key1' };

Aerospike.key(namespace, set, key [, digest])

Or, you can use .key() function.

var aerospike = require('aerospike-p');
var key = aerospike.key('ns1', 'set1', 'key1')

Client

To create a promisified Client instance:

var aerospike = require('aerospike-p');
var config = {/* ... */};
var client = new aerospike.Client(config);  // promisified Client object

All these methods have the same promisification pattern: they take the same arguements except for callback, and, they return a Promise object that resolves or rejects. For more details on the parameters and results of each methods, see corresponding non-promisified methods in Aerospike.Client.

  • Client.add(key, bins [, metadata, policy]): resolves to undefined
  • Client.append(key, bins [, metadata, policy]): resolves to [record, metadata_, key]
  • Client.batchExists(keys [, policy]): resolves to results
  • Client.batchGet(keys [, policy]): resolves to results
  • Client.batchSelect(keys [, policy]): resolves to results
  • Client.connect(): resolves to undefined
  • Client.createIntegerIndex(args): resolves to undefined
  • Client.createStringIndex(args): resolves to undefined
  • Client.execute(key, udfArgs [, policy]): resolves to response
  • Client.exists(key [, policy]): resolves to [metadata, key]
  • Client.get(key [, policy]): resolves to [record, metadata, key]
  • Client.indexRemove(namespace, index [, policy]): resolves to undefined
  • Client.indexCreateWait(namespace, index, pollInterval): resolves to undefined
  • Client.info(request [, host, policy]): resolves to [response, host]
  • Client.operate(key, operations [, metadata, policy]): resolves to [record, metadata, key]
  • Client.prepend(key, bins [, metadata, policy]): resolves to [record, metadata, key]
  • Client.put(key, record [, metadata, policy]): resolves to key
  • Client.remove(key [, policy]): resolves to key
  • Client.select(key, bins [, policy]): resolves to [record, metadata, key]
  • Client.udfRegister(udfModule [, policy]): resolves to undefined
  • Client.udfRegisterWait(udfFilename, pollInterval_[, policy]_): resolves undefined
  • Client.udfRemove(udfModule [, policy]): resolves to undefined

These methods have a slightly different patterns.

  • Client.close(): executes synchronously then it returns a Promise that resolves to undefined immediately.
  • Client.LargeList(key, binName _[, writePolicy, createModule]): returns a Promise that resolves to a promisified LargeList instance.
  • Client.query(namespace, set, statement): returns a Promise that resolves to a promisified Query instance.
  • Client.updateLogging(): executes synchronously then it returns a Promise that resolves to undefined immediately.

You can still create an original non-promisified Aerospike Client using .client() function:

var aerospike = require('aerospike-p');
var config = {/* ... */};
var client = aerospike.client(config);   // non-promisified Client object

Metadata

You can create a new Metadata instance by defining a plain object.

var metadata = { ttl: 1000, gen: 10 };

Aerospike.metadata(ttl [, gen])

Or you can use .metadata() function.

var aerospike = require('aerospike-p');
var metadata = aerospike.metadata(1000, 10); // ttl: 1000, gen: 10

Statement

You can create a Statement instance by defining a plain object.

var aerospike = require('aerospike-p');
var statement = { 
  filters: [ aerospike.filter.equal('a', 'abc') ],
  aggregationUDF: { module: 'agg_module', funcname: 'agg_func' }
}; 

UDFArgs

You can create a new UDFArgs instance by defining a plain object.

var udfArgs = { module: udf_module, funcname: udf_funcname, args: [123, 'str'] }

Aerospike.udfArgs(moduleName, funcName [, args])

Or you can use .udfArgs() function.

var aerospike = require('aerospike-p');
var udfArgs = aerospike.udfArgs(udf_module, udf_funcname, [123, 'str']);

LargeList

All these methods have the same promisification pattern: they take the same arguements except for callback, and, they return a Promise object that resolves or rejects. For more details on the parameters and results of each methods, see corresponding non-promisified methods in Aerospike.LargeList.

  • LargeList.add(value): resolves to response (value returned by LDT function add)
  • LargeList.add(values): resolves to response (value returned by LDT function add)
  • LargeList.update(value): resolves to response (value returned by LDT function add)
  • LargeList.update(values): resolves to response (value returned by LDT function add)
  • LargeList.remove(value): resolves to response (value returned by LDT function add)
  • LargeList.remove(values): resolves to response (value returned by LDT function add)
  • LargeList.removeRange(begin, end): resolves to response (count of entries removed)
  • LargeList.find(value): resolves to response (list of entries selected)
  • LargeList.find(values, udfArgs): resolves to response (list of entries selected)
  • LargeList.find(begin, end): resolves to response (list of entries selected)
  • LargeList.find(begin, end, filter): resolves to response (list of entries selected)
  • LargeList.scan(): resolves to response (all the entries in the list)
  • LargeList.filter(udfArgs): resolves to response (list of entries selected)
  • LargeList.destroy(): resolves to response (= undefined)
  • LargeList.size(): resolves to response (size of the the list)
  • LargeList.getConfig(): resolves to response (map of list config parameters)

Query

  • Query.execute(): returns a RecordStream object, which is exactly the same as the non-promisified Query.
  • Query.Info(scanid): returns a Promise object that resolves to scantInfo.

Aliases

You can use these constants, functions, or attributes in the exact same ways as you would with the original Aerospike client.

  • Aerospike.policy
  • Aerospike.filter
  • Aerospike.operations
  • Aerospike.operators
  • Aerospike.predicates
  • Aerospike.IndexType
  • Aerospike.status
  • Aerospike.scanStatus
  • Aerospike.scanPriority
  • Aerospike.log
  • Aerospike.language
  • Aerospike.Double