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:
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')), 0), 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)
Read the value of the bin.
-
Parameters:
Name Type Description bin
string The name of the bin.
- Source:
Returns:
Operation that can be passed to the
Client#operate
command.- Type
- Operation
-
<static> write(bin, value)
Update the value of the bin.
-
Parameters:
Name Type Description bin
string The name of the bin.
value
any The value to set the bin to.
- Source:
Returns:
Operation that can be passed to the
Client#operate
command.- Type
- Operation