Class: Record

Record

Aerospike Record


new Record()

Construct a new Aerospike Record instance.

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.

Since:
  • v5.0.0
Source:
Examples

Writing a new record with 5 bins while setting a record TTL.

const Aerospike = require('aerospike')

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()
  .then(client => {
    return client.put(key, bins, meta)
      .then(() => client.close())
      .catch(error => {
        client.close()
        return Promise.reject(error)
      })
  })
  .catch(error => console.error('Error:', error))

Fetching a single database record by it's key.

const Aerospike = require('aerospike')

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

Aerospike.connect()
  .then(client => {
    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 => console.error('Error:', error))

Fetching a batch of records.

const Aerospike = require('aerospike')
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_READ,
    key: new Aerospike.Key('test', 'demo', 'key3'),
    ops:[
         op.read('blob-bin')
        ]}
]
Aerospike.connect(function (error, client) {
  if (error) throw error
  client.batchRead(batchRecords, function (error, results) {
    if (error) throw error
    results.forEach(function (result) {
      console.log(result)
    })
  })
})

Applying functions on batch of records.

const Aerospike = require('aerospike')
const batchType = as.batchTypes
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(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)
    })
  })
})

Members


bins :Object

Map of bin name to bin value.

Type:
  • Object
Source:

gen :number

Record modification count.

Type:
  • number
Source:

key :Key

Unique record identifier.

Type:
Source:

ops :object

Read or write operations for this key. For BATCH_READ, ops are mutually exclusive with bin_names.

Type:
  • object
Source:

policy :object

Optional batch read/write/apply/remove policy

Type:
  • object
Source:

readAllBins :bool

batch read option If true, ignore bin_names and read all bins. If false and bin_names are set, read specified bin_names. If false and bin_names are not set, read record header (generation, expiration) only.

Type:
  • bool
Source:

ttl :number

The record's remaining time-to-live in seconds, before the record will expire and be removed by the server.

Type:
  • number
Source:

type :number

Batch record type. Values: BATCH_READ, BATCH_WRITE, BATCH_APPLY or BATCH_REMOVE

Type:
  • number
Source:

udf :object

lua module, function and optional arg list udf object

Type:
  • object
Source: