Enumeration gen

The generation policy specifies how to handle record writes based on record generation.

To use the EQ or GT generation policy (see below), the generation value to use for the comparison needs to be specified in the metadata parameter (meta) of the Client#put command.

const Aerospike = require('aerospike')
const key = new Aerospike.Key('test', 'test', 'myKey')
// 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})
}
}
Aerospike.connect(config).then(async (client) => {
await client.put(key, { foo: 'bar' })

const record = await client.get(key)
const gen = record.gen // Current generation of the record. (1 for new record.)
// Perform some command using record. Some other process might update the
// record in the meantime, which would change the generation value.
if (Math.random() < 0.1) await client.put(key, { foo: 'fox' })

try {
// Update record only if generation is still the same.
const meta = { gen }
const policy = { gen: Aerospike.policy.gen.EQ }
await client.put(key, { status: 'updated' }, meta, policy)
console.log('Record updated successfully.')
} catch (error) {
if (error.code == Aerospike.status.ERR_RECORD_GENERATION) {
console.error('Failed to update record, because generation did not match.')
}
}

client.close()
})

Enumeration Members

Enumeration Members

EQ: number

Update/delete record if expected generation is equal to server generation. Otherwise, fail.

GT: number

Update/delete record if expected generation greater than the server generation. Otherwise, fail. This is useful for restore after backup.

IGNORE: number

Do not use record generation to restrict writes.

MMNEPVFCICPMFPCPTTAAATR