Class AerospikeRecord

A record with the Aerospike database consists of one or more record "bins" (name-value pairs) and meta-data, including time-to-live and generation; a record is uniquely identified by it's key within a given namespace.

const Aerospike = require('aerospike')

// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0}),
}
}

let bins = {
int: 123,
double: 3.1415,
string: 'xyz',
bytes: Buffer.from('hello world!'),
list: [1, 2, 3],
map: {num: 123, str: 'abc', list: ['a', 'b', 'c']}
}
let meta = {
ttl: 386400 // 1 day
}
let key = new Aerospike.Key('test', 'demo', 'myKey')

Aerospike.connect(config)
.then(client => {
return client.put(key, bins, meta)
.then(() => {
client.get(key)
.then((record) => {
console.log(record)
client.close()
})
.catch(error => {
console.log(record)
client.close()
return Promise.reject(error)
})
})
.catch(error => {
client.close()
return Promise.reject(error)
})
})
.catch(error => console.error('Error:', error))
const Aerospike = require('aerospike')

// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
read : new Aerospike.ReadPolicy({socketTimeout : 0, totalTimeout : 0}),
write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0}),
}
}

let key = new Aerospike.Key('test', 'demo', 'myKey')

Aerospike.connect(config)
.then(client => {
client.put(key, {tags : ['blue', 'pink']})
.then(() => {
client.get(key)
.then(record => {
console.info('Key:', record.key)
console.info('Bins:', record.bins)
console.info('TTL:', record.ttl)
console.info('Gen:', record.gen)
})
.then(() => client.close())
.catch(error => {
client.close()
return Promise.reject(error)
})
})
.catch(error => {
client.close()
return Promise.reject(error)
})
})
.catch(error => console.error('Error:', error))

v5.0.0

const Aerospike = require('aerospike')
const op = Aerospike.operations
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
read : new Aerospike.ReadPolicy({socketTimeout : 0, totalTimeout : 0}),
write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0}),
batch : new Aerospike.BatchPolicy({socketTimeout : 0, totalTimeout : 0})

}
}

var batchRecords = [
{ type: Aerospike.batchType.BATCH_READ,
key: new Aerospike.Key('test', 'demo', 'key1'), bins: ['i', 's'] },
{ type: Aerospike.batchType.BATCH_READ,
key: new Aerospike.Key('test', 'demo', 'key2'), readAllBins: true },
{ type: Aerospike.batchType.BATCH_READ,
key: new Aerospike.Key('test', 'demo', 'key3'),
ops:[
op.read('blob-bin')
]}
]
Aerospike.connect(config, function (error, client) {
if (error) throw error
client.batchRead(batchRecords, function (error, results) {
if (error) throw error
results.forEach(function (result) {
console.log(result)

})
client.close()
})

})

v5.0.0

const Aerospike = require('aerospike')

// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
// Timeouts disabled, latency dependent on server location. Configure as needed.
policies: {
read : new Aerospike.ReadPolicy({socketTimeout : 0, totalTimeout : 0}),
write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0}),

}
}

const batchType = Aerospike.batchType
var batchRecords = [
{ type: batchType.BATCH_READ,
key: new Aerospike.Key('test', 'demo', 'key1'),
bins: ['i', 's'] },
{ type: batchType.BATCH_READ,
key: new Aerospike.Key('test', 'demo', 'key2'),
readAllBins: true },
{ type: batchType.BATCH_APPLY,
key: new Aerospike.Key('test', 'demo', 'key4'),
policy: new Aerospike.BatchApplyPolicy({
filterExpression: exp.eq(exp.binInt('i'), exp.int(37)),
key: Aerospike.policy.key.SEND,
commitLevel: Aerospike.policy.commitLevel.ALL,
durableDelete: true
}),
udf: {
module: 'udf',
funcname: 'function1',
args: [[1, 2, 3]]
}
},
{ type: batchType.BATCH_APPLY,
key: new Aerospike.Key('test', 'demo', 'key5'),
policy: new Aerospike.BatchApplyPolicy({
filterExpression: exp.eq(exp.binInt('i'), exp.int(37)),
key: Aerospike.policy.key.SEND,
commitLevel: Aerospike.policy.commitLevel.ALL,
durableDelete: true
}),
udf: {
module: 'udf',
funcname: 'function2',
args: [[1, 2, 3]]
}
}
]
Aerospike.connect(config, function (error, client) {
if (error) throw error
client.batchApply(batchRecords, udf, function (error, results) {
if (error) throw error
results.forEach(function (result) {
console.log(result)
})
})
})

Constructors

Properties

Constructors

Properties

Map of bin name to bin value.

gen: number

Record modification count.

key: Key

Unique record identifier.

ttl: number

The record's remaining time-to-live in seconds before it expires.

MMNEPVFCICPMFPCPTTAAATR