aerospike-p
aerospike-p is a promisified Aerospike Node.js client library. It internally uses the official aerospike (1.0.53) client driver.
var aerospike = ; var client = hosts: addr: '127.0.0.1' port: 3000 ; client;
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 toundefined
. - 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
.
- If the number of arguments of the original callback function was 1 (
- All returned promises reject when the underlying operation was failure (
error.code !== AEROSPIKE_OK
).- Promisified function rejects with the same
error
object.
- Promisified function rejects with the same
- 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')
torequire('aerospike-p')
in your code with no changes. (But, of course, your code is still non-promisified.)
- So you should be able to change
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 = ;var key = aerospike
Client
To create a promisified Client instance:
var aerospike = ;var config = /* ... */;var 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 = ;var config = /* ... */;var client = aerospike; // 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 = ;var metadata = aerospike; // ttl: 1000, gen: 10
Statement
You can create a Statement
instance by defining a plain object.
var aerospike = ;var statement = filters: aerospikefilter 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 = ;var udfArgs = aerospike;
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 functionadd
) - LargeList.add(values): resolves to
response
(value returned by LDT functionadd
) - LargeList.update(value): resolves to
response
(value returned by LDT functionadd
) - LargeList.update(values): resolves to
response
(value returned by LDT functionadd
) - LargeList.remove(value): resolves to
response
(value returned by LDT functionadd
) - LargeList.remove(values): resolves to
response
(value returned by LDT functionadd
) - 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