Interface ConfigOptions

interface ConfigOptions {
    authMode?: auth;
    clusterName?: string;
    connTimeoutMs?: number;
    errorRateWindow?: number;
    hosts?: string | Host[];
    log?: Log;
    loginTimeoutMs?: number;
    maxConnsPerNode?: number;
    maxErrorRate?: number;
    maxSocketIdle?: number;
    minConnsPerNode?: number;
    modlua?: ModLua;
    password?: string;
    policies?: ConfigPolicies;
    port?: number;
    rackAware?: boolean;
    rackId?: number;
    sharedMemory?: SharedMemory;
    tenderInterval?: number;
    tls?: TLSInfo;
    useAlternateAccessAddress?: boolean;
    user?: string;
}

Properties

authMode?: auth

Authentication mode used when user/password is defined.

One of the auth modes defined in auth.

clusterName?: string

Expected Cluster Name.

If not null, server nodes must return this cluster name in order to join the client's view of the cluster. Should only be set when connecting to servers that support the "cluster-name" info command.

v2.4

connTimeoutMs?: number

Initial host connection timeout in milliseconds.

The client observes this timeout when opening a connection to the cluster for the first time.

1000
errorRateWindow?: number

The number of cluster tend iterations that defines the window for maxErrorRate to be surpassed. One tend iteration is defined as tenderInterval plus the time to tend all nodes. At the end of the window, the error count is reset to zero and backoff state is removed on all nodes.

1
hosts?: string | Host[]

List of hosts with which the client should attempt to connect.

If not specified, the client attempts to read the host list from the AEROSPIKE_HOSTS environment variable or else falls back to use a default value of "localhost".

const Aerospike = require('aerospike')

const hosts = '192.168.0.1:3000,192.168.0.2:3000'
const client = await Aerospike.connect({ hosts })
const Aerospike = require('aerospike')

const hosts = [
{ addr: '192.168.0.1', port: 3000 },
{ addr: '192.168.0.2', port: 3000 }
]
const client = await Aerospike.connect({ hosts })
const Aerospike = require('aerospike')

const hosts = '192.168.0.1:example.com:3000,192.168.0.2:example.com:3000'
const client = await Aerospike.connect({ hosts })
const Aerospike = require('aerospike')

const hosts = [
{ addr: '192.168.0.1', port: 3000, tlsname: 'example.com' },
{ addr: '192.168.0.2', port: 3000, tlsname: 'example.com' }
]
const client = await Aerospike.connect({ hosts })
log?: Log

Configuration for logging done by the client.

const Aerospike = require('aerospike')

const fs = require('fs')

var debuglog = fs.openSync('./debug.log', 'w')
// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
log: {
level: Aerospike.log.DEBUG,
file: debuglog
}
}
Aerospike.connect(config, (err, client) => {
if (err) throw err
console.log("Connected. Now closing connection.")
client.close()
})
loginTimeoutMs?: number

Node login timeout in milliseconds.

5000
maxConnsPerNode?: number

Maximum number of asynchronous connections allowed per server node.

New commands will be rejected with an ERR_NO_MORE_CONNECTIONS error if the limit would be exceeded. *

100
maxErrorRate?: number

Maximum number of errors allowed per node per error_rate_window before backoff algorithm returns AEROSPIKE_MAX_ERROR_RATE for database commands to that node. If max_error_rate is zero, there is no error limit. The counted error types are any error that causes the connection to close (socket errors and client timeouts), server device overload and server timeouts.

The application should backoff or reduce the command load until AEROSPIKE_MAX_ERROR_RATE stops being returned.

If the backoff algorithm has been activated, commands will fail with AEROSPIKE_MAX_ERROR_RATE until the errorRateWindow has passed and the error count has been reset.

100
maxSocketIdle?: number

Maximum socket idle time in seconds.

Connection pools will discard sockets that have been idle longer than the maximum. The value is limited to 24 hours (86400).

It's important to set this value to a few seconds less than the server's proto-fd-idle-ms (default 60000 milliseconds or 1 minute), so the client does not attempt to use a socket that has already been reaped by the server.

Connection pools are now implemented by a LIFO stack. Connections at the tail of the stack will always be the least used. These connections are checked for maxSocketIdle once every 30 tend iterations (usually 30 seconds).

0 seconds
minConnsPerNode?: number

Minimum number of asynchronous connections allowed per server node.

Preallocate min connections on client node creation. The client will periodically allocate new connections if count falls below min connections.

Server proto-fd-idle-ms may also need to be increased substantially if min connections are defined. The proto-fd-idle-ms default directs the server to close connections that are idle for 60 seconds which can defeat the purpose of keeping connections in reserve for a future burst of activity.

If server proto-fd-idle-ms is changed, client Config#maxSocketIdle should also be changed to be a few seconds less than proto-fd-idle-ms.

0
modlua?: ModLua

Configuration values for the mod-lua user path.

If you are using user-defined functions (UDF) for processing query results (i.e. aggregations), then you will find it useful to set the modlua settings. Of particular importance is the modelua.userPath, which allows you to define a path to where the client library will look for Lua files for processing.

password?: string

The password to use when authenticating to the cluster.

policies?: ConfigPolicies

Global client policies.

The configuration defines default policies for the application. Policies define the behavior of the client, which can be global for all uses of a single type of command, or local to a single use of an command.

Each database command accepts a policy for that command as an argument. This is considered a local policy, and is a single use policy. This local policy supersedes any global policy defined.

If a value of the policy is not defined, then the rule is to fallback to the global policy for that command. If the global policy for that command is undefined, then the global default value will be used.

If you find that you have behavior that you want every use of an command to utilize, then you can specify the default policy as Config#policies.

For example, the Client#put command takes a WritePolicy parameter. If you find yourself setting the WritePolicy#key policy value for every call to Client.put, then you may find it beneficial to set the global WritePolicy in Config#policies, which all commands will use.

const Aerospike = require('aerospike')

// INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE!
var config = {
hosts: '192.168.33.10:3000',
policies: {
write: new Aerospike.WritePolicy({
key: Aerospike.policy.key.SEND,
socketTimeout : 0,
totalTimeout : 0
})
}
}

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

Aerospike.connect(config)
.then(client => {
return client.put(key, {int: 42})
.then(() => client.close())
.catch(error => {
throw error
client.close()
})
})
.catch(console.error)
port?: number

Default port to use for any host address, that does not explicitly specify a port number. Default is 3000. *

v2.4

rackAware?: boolean

Track server rack data.

This field is useful when directing read commands to the server node that contains the key and exists on the same rack as the client. This serves to lower cloud provider costs when nodes are distributed across different racks/data centers.

rackId config, policy.replica.PREFER_RACK replica policy, and server rack configuration must also be set to enable this functionality.

false

3.8.0

rackId?: number

Rack where this client instance resides.

rackAware config, policy.replica.PREFER_RACK replica policy, and server rack configuration must also be set to enable this functionality.

0

3.8.0

sharedMemory?: SharedMemory

Shared memory configuration.

This allows multiple client instances running in separate processes on the same machine to share cluster status, including nodes and data partition maps. Each shared memory segment contains state for one Aerospike cluster. If there are multiple Aerospike clusters, a different key must be defined for each cluster.

Notes

const Aerospike = require('aerospike')
const cluster = require('cluster')

const config = {
sharedMemory: {
key: 0xa5000000
}
}
const client = Aerospike.client(config)
const noWorkers = 4

if (cluster.isMaster) {
// spawn new worker processes
for (var i = 0; i < noWorkers; i++) {
cluster.fork()
}
} else {
// connect to Aerospike cluster in each worker process
client.connect((err) => { if (err) throw err })

// handle incoming HTTP requests, etc.
// http.createServer((request, response) => { ... })

// close DB connection on shutdown
client.close()
}
tenderInterval?: number

Polling interval in milliseconds for cluster tender.

1000
tls?: TLSInfo

Configure Transport Layer Security (TLS) parameters for secure connections to the database cluster. TLS connections are not supported as of Aerospike Server v3.9 and depend on a future server release.

v2.4

useAlternateAccessAddress?: boolean

Whether the client should use the server's alternate-access-address instead of the access-address.

false

v3.7.1

user?: string

The user name to use when authenticating to the cluster.

Leave empty for clusters running without access management. (Security features are available in the Aerospike Database Enterprise Edition.)

MMNEPVFCICPMFPCPTTAAATR