Module: aerospike

The Aerospike module is the main entry point for the Aerospike Node.js Client API. It provides methods for creating new client instances that connect to a specific Aerospike server cluster.

Source:

Members


<static> AerospikeError

AerospikeError class

In case of any errors during the database operation the client will return an AerospikeError instance (either through the provided callback or when the returned Promise gets resolved).

Source:

<static, readonly> auth :number

Enumeration of auth modes

Authentication mode when user/password is defined.

Note: The Node.js client's TLS support is currently limited to Linux, and therefore secure, external authentication (e.g. LDAP) is only supported on Linux as well. External authentication can be used on macOS or Windows but it will not be secure!

Type:
  • number
Properties:
Name Type Description
INTERNAL number

Use internal authentication only. Hashed password is stored on the server. Do not send clear password. This is the default.

EXTERNAL number

Use external authentication (like LDAP). Specific external authentication is configured on server. If TLS is enabled, send clear password on node login via TLS. Throws exception, if TLS is not enabled.

EXTERNAL_INSECURE number

Use external authentication (like LDAP). Specific external authentication is configured on server. Send clear password on node login whether or not TLS is enabled. This mode should only be used for testing purposes because it is not secure authentication.

Source:
Example

Using external authentication mode, e.g. to use LDAP authentication

const Aerospike = require('aerospike')

const config = {
  user: process.env.ADMIN_USER,
  password: process.env.ADMIN_PASSWORD,
  authMode: Aerospike.auth.EXTERNAL
}

Aerospike.connect(config).then(async (client) => {
  const info = await client.infoAny().then(Aerospike.info.parse)
  console.info(info)
  client.close()
})

<static> bitwise

aerospike/bitwise module

The bitwise module defines operations on the bytes data type.

Source:

<static> cdt

aerospike/cdt module

The cdt module provides the CdtContext class for operations on nested lists and maps.

Source:

<static> Client

Client class

The main interface of the Aerospike client. Through the Client class, commands such as put, get or query can be sent to an Aerospike database cluster.

Source:

<static> Config

Config class

The Config class contains the settings for an Aerospike client instance, including the list of seed hosts, default policies, and other settings.

Source:

<static> Double

Double class

All the decimal values with valid fractions (e.g. 123.45) will be stored as double data type in Aerospike. To store decimal values with 0 fraction as double, the value needs to be wrapped in a Double class instance.

Source:

<static> features

aerospike/features module

The features module contains a list of the feature strings used by the Aerospike server.

Source:

<static> filter

aerospike/filter module

The filter module provides functions to create secondary index filter predicates for use in query operations via the Client#query command.

Source:

<static> GeoJSON

GeoJSON class

Representation of a GeoJSON value. Since GeoJSON values are JSON objects they need to be wrapped in the GeoJSON class so that the client can distinguish them from other types of objects.

Source:

<static> hll

aerospike/hll module

The hll module defines operations on the HyperLogLog data type.

Since:
  • v3.16.0
Source:

<static, readonly> indexDataType :number

Enumeration of secondary index data types.

Type:
  • number
Properties:
Name Type Description
STRING number

Values contained in the secondary index are strings.

NUMERIC number

Values contained in the secondary index are integers.

GEO2DSPHERE number

Values contained in the secondary index are GeoJSON values (points or polygons).

Source:
See:

<static, readonly> indexType :number

Enumeration of secondary index types.

Type:
  • number
Properties:
Name Type Description
DEFAULT number

Default secondary index type for bins containing scalar values (i.e. integer, string).

LIST number

Secondary index for bins containing ⇑Lists; the index will be build over the individual entries of the list.

MAPKEYS number

Secondary index for bins containing ⇑Maps; the index will be build over the individual keys of the map entries.

MAPVALUES number

Secondary index for bins containing ⇑Maps; the index will be build over the individual values of the map entries.

Source:
See:

<static> info

aerospike/info module

The info protocol provides access to configuration and statistics for the Aerospike server. The info module provides utility functions for parsing the info data returned by the Aerospike server.

Source:

<static, readonly> jobStatus :number

Enumeration of job status codes.

Type:
  • number
Properties:
Name Type Description
UNDEF number

The job status is undefined. This is likely due to the status not being properly checked.

INPROGRESS number

The job is currently running.

COMPLETED number

The job completed successfully.

Source:
See:
  • Job#infoCallback returns the job status.

<static> Key

Key class

A key uniquely identifies a record in the Aerospike database within a given namespace.

Source:

<static, readonly> language :number

Enumeration of UDF types.

Type:
  • number
Properties:
Name Type Description
LUA number

Lua (only supported UDF type at the moment)

Source:

<static> lists

aerospike/lists module

The lists module defines operations on the Lists complex data type.

Source:

<static, readonly> log :number

Enumeration of log levels

Type:
  • number
Properties:
Name Type Description
OFF number

Turn off logging

ERROR number

Log messages at ERROR level

WARN number

Log messages at WARN level or below

INFO number

Log messages at INFO level or below

DEBUG number

Log messages at DEBUG level or below

TRACE number

Log messages at TRACE level or below

Source:
See:
Example

Setting log level for new client

const Aerospike = require('aerospike')

var config = {
  log: { level: Aerospike.log.INFO }
}
Aerospike.connect(config, (error, client) => {
  if (error) throw error

  var key = new Aerospike.Key('test', 'demo', 'k1')
  client.get(key, (error, record) => {
    if (error) throw error
    console.info(record)
    client.close()
  })
})

<static, constant> maps

aerospike/maps module

The maps module defines operations on the Maps complex data type.

Source:

<static> operations

aerospike/operations module

The operations module provides functions to create operations for the Client#operate command.

Source:

<static, constant> policy

aerospike/policy module

The policy module defines policies and policy values that define the behavior of database operations.

Source:

<static> predexp

aerospike/predexp module

The predexp module provides functions to create predicate expressions for use in query operations via the Client#query command.

Source:

<static> Record

Record class

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

Source:

<static, readonly> regex :number

POSIX regex compilation flags.

Type:
  • number
Properties:
Name Type Default Description
BASIC number 0

Use basic regular expression syntax.

EXTENDED number 1

Use extended regular expression syntax.

ICASE number 2

Ignore case when matching.

NEWLINE number 4

Anchors do not match at newline characters in the string.

Source:
See:

<static, readonly> scanPriority :number

Enumeration of priority levels for a scan operation.

Type:
  • number
Properties:
Name Type Description
AUTO number

The cluster will auto adjust the scan priority.

LOW number

Low scan priority.

MEDIUM number

Medium scan priority.

HIGH number

High scan priority.

Source:
See:

<static> status

aerospike/status module

The status module contains a list of the status codes returned by the Aerospike server.

Source:

<static, readonly> ttl :number

Enumertion of special TTL (time-to-live) values.

Instead of specifying a TTL in seconds, you can set the TTL to one of these special values when creating or updating a record.

Type:
  • number
Properties:
Name Type Description
NAMESPACE_DEFAULT number

Use the default TTL value for the namespace of the record.

NEVER_EXIRE number

Never expire the record.

DONT_UPDATE number

Update the record without changing the record's TTL value. Requires Aerospike Server version 3.10.1 or later.

Source:
Example

Use ttl.DONT_UPDATE to change the value of a record bin without changing the records expiry time

const Aerospike = require('aerospike')
const Key = Aerospike.Key

Aerospike.connect((error, client) => {
  if (error) throw error
  let key = new Key('test', 'demo', 'key1')
  let bins = { 'int': 1 }
  let meta = { ttl: 86400 }

  client.put(key, record, meta, (error) => {
    if (error) throw error

    bins = { 'int': 2 }
    meta = { ttl: Aerospike.ttl.DONT_UPDATE }
    client.put(key, bins, meta, (error) => {
      if (error) throw error

      client.get(key, (error, record) => {
        if (error) throw error

        console.log(record.bins.int) // => 2
        console.log(record.ttl)      // => 86400
        client.close()
      })
    })
  })
})

Methods


<static> client( [config])

Creates a new Client instance.

Parameters:
Name Type Argument Description
config Config <optional>

The configuration for the client.

Source:

<static> connect( [config] [, callback])

Creates a new Client instance and connects to the Aerospike cluster.

Calling Aerospike.connect(config, (err, client) -> { ... }) is equivalent to calling

const client = Aerospike.client(config)
client.connect((err) -> { ... })
Parameters:
Name Type Argument Description
config Config <optional>

The configuration for the client.

callback connectCallback <optional>

The function to call, once the client is connected to the cluster successfully.

Source:
Returns:

If no callback function is passed, the function returns a Promise resolving to the connected client.

Type
Promise
Examples

Using callback function

const Aerospike = require('aerospike')

let config = { ... }
Aerospike.connect(config, (error, client) => {
  if (error) {
    console.error('Failed to connect to cluster: %s', error.message)
    process.exit()
  } else {
    // client is ready to accept commands
    client.close()
  }
})

Returning a Promise

const Aerospike = require('aerospike')

let config = { ... }
Aerospike.connect(config)
  .then(client => {
    // client is ready to accept commands
    return client.get(key)
      .then(record => console.info(record))
      .then(() => client.close())
      .catch(error => {
        console.error('Failed to get record: %s', error.message)
        client.close()
      })
  })
  .catch(error => {
    console.error('Failed to connect to cluster: %s', error.message)
  })

<static> releaseEventLoop()

Release event loop resources held by the module, which could keep the Node.js event loop from shutting down properly.

This method releases some event loop resources held by the Aerospike module and the Aerospike C client library, such as libuv handles and timers. If not released, these handles will prevent the Node.js event loop from shutting down, i.e. it will keep your application from terminating.

The Aerospike module keeps an internal counter of active Client instances, i.e. instances which have not been close()'d yet. If a client is closed and the counter reaches zero, this method will be called automatically, unless Client#close is called with releaseEventLoop set to false. (The default is true.)

If an application needs to create multiple client instance, i.e. to connect to multiple, different clusters, the event loop resources will be managed automatically, as long as at least once client instance is active at any given time, until the application terminates.

If, however, there could be one or more intermittent time periods, during which no client is active (i.e. the internal client counter reaches zero), then the clients need to be closed with releaseEventLoop set to false and the event loop needs to be released explicitly by calling releaseEventLoop().

Source:

<static> setDefaultLogging(log)

Sets the global, default log level and destination. The default log settings are used for all new client instances, unless different log settings are supplied in the client's configuration.

The global log settings are also used to control the logging of the Aerospike C client SDK which is included in the aerospike native add-on. The C client SDK log settings are global and cannot be set separately per Client instance.

Parameters:
Name Type Description
log Object
Properties
Name Type Argument Description
level Number <optional>

Log level; see module:aerospike.log for details.

file Number <optional>

File descriptor returned by fs.open() or one of process.stdout.fd or process.stderr.fd.

Since:
  • v3.1.0
Source:
Example
const Aerospike = require('aerospike')

Aerospike.setDefaultLogging({
  level: Aerospike.log.TRACE
})

<static> setupGlobalCommandQueue(policy)

Configures the global command queue. (Disabled by default.)

Note that there is only one instance of the command queue that is shared by all client instances, even client instances connected to different Aerospike clusters. The setupGlobalCommandQueue method must be called before any clien} instances are connected.

Parameters:
Name Type Description
policy CommandQueuePolicy

Set of policy values governing the behaviour of the global command queue.

Source:
See: