Infinispan Hot Rod JS Client

0.13.0 · active · verified Tue Apr 21

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import infinispan from 'infinispan';

async function runClient() {
  let client;
  try {
    // Connect to Infinispan Server on localhost:11222
    // and specify a cache name, e.g., 'myCache'.
    // Ensure an Infinispan server is running and 'myCache' exists or is configured for autostart.
    client = await infinispan.client(
      { host: process.env.INFINISPAN_HOST ?? '127.0.0.1', port: parseInt(process.env.INFINISPAN_PORT ?? '11222', 10) },
      { cacheName: process.env.INFINISPAN_CACHE_NAME ?? 'myCache' }
    );
    console.log('Successfully connected to Infinispan!');

    const key = 'myKey';
    const value = 'myValue';

    // Put an entry into the cache
    await client.put(key, value);
    console.log(`Put: '${key}' -> '${value}'`);

    // Get the entry from the cache
    const retrievedValue = await client.get(key);
    console.log(`Get: '${key}' -> '${retrievedValue}'`);

    // Check if the key exists
    const contains = await client.containsKey(key);
    console.log(`Contains key '${key}': ${contains}`);

  } catch (error) {
    console.error('Error interacting with Infinispan:', error.message);
  } finally {
    if (client) {
      await client.disconnect();
      console.log('Disconnected from Infinispan.');
    }
  }
}

runClient();

view raw JSON →