- Description:
This module provides functions to easily create read/write operations using Aerospike expressions to be performed on a record via the
Client#operate
command.
- Source:
- See:
This module provides functions to easily create read/write operations
using Aerospike expressions to be performed on a record via
the Client#operate
command.
Example
const Aerospike = require('aerospike')
const op = Aerospike.operations
const exp = Aerospike.exp
const key = new Aerospike.Key('test', 'demo', 'mykey1')
const tempBin = 'ExpVar' // this bin is to hold expression read operation output
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
const config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
operate : new Aerospike.OperatePolicy({socketTimeout : 0, totalTimeout : 0}),
write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0})
}
}
var ops = [
op.append('a', 'xyz'),
op.incr('b', 10),
exp.operations.read(tempBin,
exp.add(exp.binInt('b'), exp.binInt('b')),
exp.expReadFlags.DEFAULT),
op.read('a'),
op.read('b')
]
Aerospike.connect(config, (error, client) => {
if (error) throw error
client.put(key, { a: 'abc', b: 42 }, (error) => {
if (error) throw error
client.operate(key, ops, (error, record) => {
if (error) throw error
console.log(record.bins) // => { a: 'abcxyz', b: 52, ExpVar: 104 }
client.close()
})
})
})
Methods
(static) read(bin, name, exp, flags) → {Operation}
Read the value of the bin.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
bin |
string | The name of the bin. |
name |
string | The name of bin to store expression result |
exp |
AerospikeExp | The expression to evaluate |
flags |
Expression read flags. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Operation
(static) write(bin, value, binName, exp, flags) → {Operation}
Update the value of the bin.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
bin |
string | The name of the bin. |
value |
any | The value to set the bin to. |
binName |
string | The variable name of read expression result. This name can be used as the bin name when retrieving bin results from the record. |
exp |
AerospikeExp | The expression to evaluate |
flags |
Expression write flags. |
Returns:
Operation that can be passed to the Client#operate
command.
- Type
- Operation