Module: aerospike/operations

This module provides functions to easily define operations to be performed on a record via the Client#operate command.

Source:
See:

Example

const Aerospike = require('aerospike')
const op = Aerospike.operations
const key = new Aerospike.Key('test', 'demo', 'mykey1')
// 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: {
    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),
  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) // => { b: 52 }
      client.close()
    })
  })
})

Classes

Operation

Methods


<static> add(bin, value)

Increment the value of the bin by the given value.

The bin must contain either an Integer or a Double, and the value must be of the same type.

Parameters:
Name Type Description
bin string

The name of the bin.

value number | Object

The number|Double value to increment the bin by.

Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Operation

<static> append(bin, value)

Append the value to the bin.

The bin must contain either String or a Byte Array, and the value must be of the same type.

Parameters:
Name Type Description
bin string

The name of the bin.

value string | Buffer

The value to append to the bin.

Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Operation

<static> delete()

Deletes the record.

Returns true on success. Otherwise an error occurred.

Since:
  • v3.14.0
Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Operation

<static> incr()

Alias for the module:aerospike/operations.add operation.

Source:

<static> prepend(bin, value)

Prepend the value to the bin.

The bin must contain either String or a Byte Array, and the value must be of the same type.

Parameters:
Name Type Description
bin string

The name of the bin.

value string | Buffer

The value to prepend to the bin.

Source:
Returns:

Operation that can be passed to the Client#operate command.

Type
Operation

<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> touch( [ttl])

Update the TTL (time-to-live) for a record.

If the optional ttl parameter is not specified, the server will reset the record's TTL value to the default TTL value for the namespace.

Parameters:
Name Type Argument Default Description
ttl number <optional>
Aerospike.ttl.NAMESPACE_DEFAULT

The new, relative TTL to set for the record, when it is touched.

Source:
See:
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