Construct an instance of the Config class.
Optional
config: ConfigOptionsOptional
authAuthentication mode used when user/password is defined.
One of the auth modes defined in auth.
Optional
clusterExpected 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.
Optional
connInitial host connection timeout in milliseconds.
The client observes this timeout when opening a connection to the cluster for the first time.
Optional
errorThe 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.
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 })
Optional
logConfiguration 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()
})
Optional
loginNode login timeout in milliseconds.
Optional
maxMaximum 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. *
Optional
maxMaximum 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.
Optional
maxMaximum 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).
Optional
minMinimum 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
.
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.
Optional
passwordThe password to use when authenticating to the cluster.
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 write 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)
Default port to use for any host address, that does not explicitly specify a port number. Default is 3000. *
Optional
rackTrack 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.
Optional
rackRack 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.
Optional
sharedShared 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.
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()
}
Optional
tenderPolling interval in milliseconds for cluster tender.
Optional
tlsConfigure 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.
Whether the client should use the server's
alternate-access-address
instead of the
access-address
.
Optional
userThe 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.)
Set default policies from the given policy values.
Optional
policies: ConfigPoliciesone or more default policies
The Config class contains the settings for an Aerospike client instance, including the list of seed hosts, default policies, and other settings.
Throws
If invalid config values are passed.
Example