Class: Client

Client(args, options)

new Client(args, options)

Infinispan client constructor taking an optional initial address, or multiple addresses, to which the client will try to connect to, as well as optional configuration settings.
Parameters:
Name Type Description
args ServerAddress | Array.<ServerAddress> Optional single or multiple addresses to which to connect. If none provided, the client will connect to localhost:11222 address by default.
options module:infinispan.ClientOptions Optional configuration settings.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed once the connection has been established. The promise will be completed with a client instance on which operations can invoked.
Examples
client({port: 11222, host: 'localhost'})
client([{port: 11322, host: 'node1'}, {port: 11422, host: 'node2'}])
client({port: 11522, host: 'myhost'}, {version: '2.2'})
client([{port: 11522, host: 'myhost'}, {port: 11622, host: 'myhost'}],
       {version: '2.2', cacheName: 'myCache'})

Methods

addListener(event, listener, optsnullable) → {module:promise.Promise.<String>}

Add an event listener.
Parameters:
Name Type Attributes Description
event String Event to add listener to. Possible values are: 'create', 'modify', 'remove' and 'expiry'.
listener function Function to invoke when the listener event is received. 'create' and 'modify' events callback the function with key, entry version and listener id. 'remove' and 'expiry' events callback the function with key and listener id.
opts ListenOptions <nullable>
Options for adding listener.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with the identifier of the listener. This identifier can be used to register multiple callbacks with the same listener, or to remove the listener.
Type
module:promise.Promise.<String>

addScript(scriptName, script) → {module:promise.Promise}

Add script to server(s).
Parameters:
Name Type Description
scriptName String Name of the script to store.
script String Script to store in server.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed when the script has been stored.
Type
module:promise.Promise

clear() → {module:promise.Promise}

Clear all entries stored in server(s).
Since:
  • 0.3
Source:
Returns:
A promise that will be completed when the clear has been completed.
Type
module:promise.Promise

containsKey(k) → {module:promise.Promise.<boolean>}

Check whether the given key is present.
Parameters:
Name Type Description
k String | Object Key to check for presence.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with true if there is a value associated with the key, or false otherwise.
Type
module:promise.Promise.<boolean>

disconnect() → {module:promise.Promise}

Disconnect client from backend server(s).
Since:
  • 0.3
Source:
Returns:
A promise that will be completed once client has completed disconnection from server(s).
Type
module:promise.Promise

execute(scriptName, paramsnullable) → {module:promise.Promise.<(String|Array.<String>)>}

Execute the named script passing in optional parameters.
Parameters:
Name Type Attributes Description
scriptName String Name of the script to execute.
params Array.<ExecParams> <nullable>
Optional array of named parameters to pass to script in server.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with either the value returned by the script after execution for local scripts, or an array of values returned by the script when executed in multiple servers for distributed scripts.
Type
module:promise.Promise.<(String|Array.<String>)>

get(k) → {module:promise.Promise.<?String>}

Get the value associated with the given key parameter.
Parameters:
Name Type Description
k String | Object Key to retrieve.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with the value associated with the key, or undefined if the value is not present.
Type
module:promise.Promise.<?String>

getAll(keys) → {module:promise.Promise.<Array.<Entry>>}

Retrieves all of the entries for the provided keys.
Parameters:
Name Type Description
keys Array.<String> | Array.<Object> Keys to find values for.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with an array of entries for all keys found. If a key does not exist, there won't be an entry for that key in the returned array.
Type
module:promise.Promise.<Array.<Entry>>

getTopologyInfo() → {TopologyInfo}

Get server topology related information.
Since:
  • 0.3
Source:
Returns:
An object instance that can be used to query diverse information related to the server topology information.
Type
TopologyInfo

getWithMetadata(k) → {module:promise.Promise.<?MetadataValue>}

Get the value and metadata associated with the given key parameter.
Parameters:
Name Type Description
k String | Object Key to retrieve.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with the value and metadata associated with the key, or undefined if the value is not present.
Type
module:promise.Promise.<?MetadataValue>

iterator(batchSize, optsnullable) → {module:promise.Promise.<Iterator>}

Iterate over the entries stored in server(s).
Parameters:
Name Type Attributes Description
batchSize Number The number of entries transferred from the server at a time.
opts IteratorOptions <nullable>
Optional iteration settings.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with an iterator that can be used to retrieve stored elements.
Type
module:promise.Promise.<Iterator>

ping() → {module:promise.Promise}

Pings the server(s).
Since:
  • 0.3
Source:
Returns:
A promise that will be completed when ping response was received.
Type
module:promise.Promise

put(k, v, optsnullable) → {module:promise.Promise.<?(String|Object)>}

Associates the specified value with the given key.
Parameters:
Name Type Attributes Description
k String | Object Key with which the specified value is to be associated.
v String | Object Value to be associated with the specified key.
opts StoreOptions <nullable>
Optional store options.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with undefined unless 'previous' option has been enabled and a previous value exists, in which case it would return the previous value.
Type
module:promise.Promise.<?(String|Object)>

putAll(pairs, opts) → {module:promise.Promise}

Stores all of the mappings from the specified entry array.
Parameters:
Name Type Description
pairs Array.<Entry> key/value pair mappings to be stored
opts MultiStoreOptions Optional storage options to apply to all entries.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed when all entries have been stored.
Type
module:promise.Promise

putIfAbsent(k, v, optsnullable) → {module:promise.Promise.<(Boolean|String|Object)>}

Conditional store operation that associates the key with the given value if the specified key is not already associated with a value.
Parameters:
Name Type Attributes Description
k String | Object Key with which the specified value is to be associated.
v String | Object Value to be associated with the specified key.
opts StoreOptions <nullable>
Optional store options.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with true if the mapping was stored, or false if the key is already present. If the 'previous' option is enabled, it returns the existing value or undefined if the key does not exist.
Type
module:promise.Promise.<(Boolean|String|Object)>

remove(k, optsnullable) → {module:promise.Promise.<(Boolean|String|Object)>}

Removes the mapping for a key if it is present.
Parameters:
Name Type Attributes Description
k String | Object Key whose mapping is to be removed.
opts RemoveOptions <nullable>
Optional remove options.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with true if the mapping was removed, or false if the key did not exist. If the 'previous' option is enabled, it returns the value before removal or undefined if the key did not exist.
Type
module:promise.Promise.<(Boolean|String|Object)>

removeListener(listenerId) → {module:promise.Promise}

Remove an event listener.
Parameters:
Name Type Description
listenerId String Listener identifier to identify listener to remove.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed when the listener has been removed.
Type
module:promise.Promise

removeWithVersion(k, version, optsnullable) → {module:promise.Promise.<(Boolean|String|Object)>}

Removes the given entry only if its version matches the supplied version.
Parameters:
Name Type Attributes Description
k String | Object Key whose mapping is to be removed.
version Buffer binary buffer version that should match the one in the server for the operation to succeed. Version information can be retrieved with getWithMetadata method.
opts RemoveOptions <nullable>
Optional remove options.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with true if the version matches and the mapping was removed, otherwise it returns false if not removed because key does not exist or version sent does not match server-side version. If the 'previous' option is enabled, it returns the value that was removed if the version matches. If the version does not match, the current value is returned. Fianlly if the key did not exist it returns undefined.
Type
module:promise.Promise.<(Boolean|String|Object)>

replace(k, v, optsnullable) → {module:promise.Promise.<(Boolean|String|Object)>}

Conditional store operation that replaces the entry for a key only if currently mapped to a given value.
Parameters:
Name Type Attributes Description
k String | Object Key with which the specified value is associated.
v String | Object Value expected to be associated with the specified key.
opts StoreOptions <nullable>
Optional store options.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with true if the mapping was replaced, or false if the key does not exist. If the 'previous' option is enabled, it returns the value that was replaced or undefined if the key did not exist.
Type
module:promise.Promise.<(Boolean|String|Object)>

replaceWithVersion(k, v, version, optsnullable) → {module:promise.Promise.<(Boolean|String|Object)>}

Replaces the given value only if its version matches the supplied version.
Parameters:
Name Type Attributes Description
k String | Object Key with which the specified value is associated.
v String | Object Value expected to be associated with the specified key.
version Buffer binary buffer version that should match the one in the server for the operation to succeed. Version information can be retrieved with getWithMetadata method.
opts StoreOptions <nullable>
Optional store options.
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with true if the version matches and the mapping was replaced, otherwise it returns false if not replaced because key does not exist or version sent does not match server-side version. If the 'previous' option is enabled, it returns the value that was replaced if the version matches. If the version does not match, the current value is returned. Fianlly if the key did not exist it returns undefined.
Type
module:promise.Promise.<(Boolean|String|Object)>

size() → {module:promise.Promise.<Number>}

Count of entries in the server(s).
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with the number of entries stored.
Type
module:promise.Promise.<Number>

stats() → {module:promise.Promise.<Array.<StatsItem>>}

Retrieve various statistics from server(s).
Since:
  • 0.3
Source:
Returns:
A promise that will be completed with an array of statistics, where each element will have a single property. This single property will have the statistic name as property name and statistic value as property value.
Type
module:promise.Promise.<Array.<StatsItem>>

toString()

Get client information represented as a string.
Since:
  • 0.4
Source: