The `infinispan` package provides an asynchronous, event-driven JavaScript client for Node.js applications to interact with Infinispan data grids using the Hot Rod protocol. Currently at version 0.13.0, it leverages Promises for all asynchronous operations, simplifying error handling and chaining. The client offers comprehensive CRUD capabilities, compare-and-swap operations, expiration management with flexible time units, bulk operations (putAll, getAll, clear), and advanced features like remote cache listeners, server-side script execution, and statistics retrieval. A key differentiator is its robust cluster awareness, supporting consistent hashing for key-based operations, dynamic topology discovery for nodes joining or leaving, and automatic multi-site failover with manual switching capabilities. It's under active development, indicating ongoing feature additions and improvements.
npm install infinispanVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to connect to an Infinispan server, put a key-value pair into a named cache, retrieve it, and check for its existence, then disconnect.
Upgrade to `infinispan` client version 0.6.0 or newer to use native JSON objects for keys and values, or manually serialize/deserialize to strings.
Ensure the `infinispan` client version is compatible with your Infinispan Server version. Consult the client's installation guide for precise compatibility matrix.
Pin your client version (e.g., `~0.13.0` or `0.13.0`) and review release notes thoroughly for any updates before upgrading, especially in production environments. Regular testing is recommended.
Configure the client with appropriate `authentication` options including `userName`, `password`, and `saslMechanism` (e.g., 'DIGEST-MD5', 'SCRAM'). Create a user on the Infinispan server if not already done.
When initializing the client for query operations, include `{ dataFormat: 'application/x-protostream' }` in the client options.Verify that your Infinispan server is running and listening on the configured host and port (default is 11222). Check firewall rules. Ensure host/port in `infinispan.client()` call are correct.
Ensure you are using `import infinispan from 'infinispan';` for ESM, and then `await infinispan.client(...)`. For CommonJS, use `const infinispan = require('infinispan');`.Ensure the cache `myCache` is created and configured on your Infinispan server. You might need to use the server console or management API to create it, or configure the server for automatic cache creation.
Always use `.catch()` with Promise chains or `try...catch` blocks with `async/await` to handle potential errors from all client operations.