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> Client
Client
class -
The main interface of the Aerospike client. Commands such as put, get or query can be sent to an Aerospike database cluster using the Client class.
- 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> 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> Key
Key
class -
A key uniquely identifies a record in the Aerospike database within a given namespace.
- 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> 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
- Source:
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.
AUTH_PKI
number Use PKI authentication. Authentication and authorization is based on a certificate. No user name or password needs to be configured. Requires mTLS and a client certificate.
Examples
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 }
Using PKI authentication mode
const Aerospike = require('aerospike') const config = { hosts: [ { addr: 'bob-cluster-a', port: process.env.PORT} ], tls: { cafile: process.env.CAFILE, keyfile: process.env.KEYFILE, certfile: process.env.CERT, } authMode: Aerospike.auth.AUTH_PKI, } Aerospike.connect(config).then(async (client) => { const info = await client.infoAny().then(Aerospike.info.parse) console.info(info) client.close() })
-
<static> batchType
aerospike/batch_type
module -
The
aerospike/batch_type
module contains a list of batch record types.- Source:
-
<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 theCdtContext
class for operations on nested lists and maps.- 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 (SI) filter predicates for use in query operations via theClient#query
command.- Source:
-
<static> hll
aerospike/hll
module -
The
hll
module defines operations on the HyperLogLog data type.- Since:
-
- v3.16.0
- Source:
-
<static> indexDataType :number
Enumeration of SI data types.
-
Type:
- number
- Source:
- See:
Properties:
Name Type Description STRING
number Values contained in the SI are strings.
NUMERIC
number Values contained in the SI are integers.
GEO2DSPHERE
number Values contained in the SI are GeoJSON values (points or polygons).
-
<static> indexType :number
Enumeration of SI types.
-
Type:
- number
- Source:
- See:
Properties:
Name Type Description DEFAULT
number Default SI type for bins containing scalar values (i.e. integer, string).
LIST
number SI for bins containing ⇑Lists; The index will be built over the individual entries of the list.
MAPKEYS
number SI for bins containing ⇑Maps; The index will be built over the individual keys of the map entries.
MAPVALUES
number SI for bins containing ⇑Maps; The index will be built over the individual values of the map entries.
-
<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> jobStatus :number
Enumeration of job status codes.
-
Type:
- number
- Source:
- See:
-
Job#infoCallback
returns the job status.
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.
-
<static> language :number
Enumeration of UDF types.
-
Type:
- number
- Source:
Properties:
Name Type Description LUA
number Lua (only supported UDF type at the moment)
-
<static> lists
aerospike/lists
module -
The
lists
module defines operations on the Lists complex data type.- Source:
-
<static> log :number
Enumeration of log levels
-
Type:
- number
- Source:
- See:
-
Config#log
to set the log level for a specific client instancemodule:aerospike.setDefaultLogging
to set the global default log settings, incl. logging of the Aerospike C client library.
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
Example
Setting log level for new client
const Aerospike = require('aerospike') // INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE! var config = { hosts: '192.168.33.10:3000', log: { level: Aerospike.log.DEBUG }, // Timeouts disabled, latency dependent on server location. Configure as needed. policies: { read : new Aerospike.ReadPolicy({socketTimeout : 0, totalTimeout : 0}), write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0}) } } Aerospike.connect(config, (error, client) => { if (error) throw error var key = new Aerospike.Key('test', 'demo', 'k1') client.put(key, {example: 31}, (error) => { if (error) throw error client.get(key, (error, record) => { 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 theClient#operate
command.- Source:
-
<static> policy
aerospike/policy
module -
The
policy
module defines policies and policy values that define the behavior of database operations.- Source:
-
<static> regex :number
POSIX regex compilation flags.
-
Type:
- number
- Source:
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.
-
<static> status
aerospike/status
module -
The
status
module contains a list of the status codes returned by the Aerospike server.- Source:
-
<static> 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
- Source:
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 server 3.10.1 or later.
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 // 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: { read : new Aerospike.ReadPolicy({socketTimeout : 0, totalTimeout : 0}), write : new Aerospike.WritePolicy({socketTimeout : 0, totalTimeout : 0}) } } Aerospike.connect(config, (error, client) => { if (error) throw error let key = new Key('test', 'demo', 'key1') let bins = { 'int': 1 } let meta = { ttl: 86400 } client.put(key, bins, 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() }) }) }) })
-
<inner, constant> exp
aerospike/exp
module -
The
exp
module provides functions to create expressions for use in key operations via theClient#operate
command.- Source:
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.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
Connection can be established using the
aerospike
module.const Aerospike = require('aerospike') // INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE! var config = { hosts: '192.168.33.10:3000', } Aerospike.connect(config, (err, client) => { console.log("Connected. Closing now.") client.close() })
Connection can also be established using the
Client
module.const Aerospike = require('aerospike') // INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE! var config = { hosts: '192.168.33.10:3000', } const client = Aerospike.client(config) client.connect((err) => { console.log("Connected. Closing now.") client.close() })
A connection established using callback function.
const Aerospike = require('aerospike') // INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE! var config = { hosts: '192.168.33.10:3000', } 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 console.log("Connected. Now closing connection.") client.close() } })
A connection established by returning a Promise.
const Aerospike = require('aerospike') // INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE! var config = { hosts: '192.168.33.10:3000', } Aerospike.connect(config) .then(client => { // client is ready to accept commands console.log("Connected. Now Closing Connection.") 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 beenclose()
'd yet. If a client is closed and the counter reaches zero, this method will be called automatically, unlessClient#close
is called withreleaseEventLoop
set tofalse
. (The default istrue
.)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 tofalse
and the event loop needs to be released explicitly by callingreleaseEventLoop()
.- 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 perClient
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 ofprocess.stdout.fd
orprocess.stderr.fd
.- Since:
-
- v3.1.0
- Source:
Example
const Aerospike = require('aerospike') // INSERT HOSTNAME AND PORT NUMBER OF AEROSPIKE SERVER NODE HERE! var config = { hosts: '192.168.33.10:3000', } Aerospike.setDefaultLogging({ level: Aerospike.log.TRACE }) 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 console.log("Connected. Now closing connection.") client.close() } })
-
<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 client instances are connected.Parameters:
Name Type Description policy
CommandQueuePolicy Set of policy values governing the behaviour of the global command queue.
- Source:
- See:
-
CommandQueuePolicy
for more information about the use of the command queue.