Infinispan Server includes an endpoint that implements the RESP3 protocol and allows you to interact with remote caches using Redis clients.

1. Infinispan RESP endpoint

The RESP endpoint is enabled by default on the single-port endpoint. Redis client connections will automatically be detected and routed to the internal connector. The RESP endpoint works with:

  • Standalone Infinispan Server deployments, exactly like standalone Redis, where each server instance runs independently of each other.

  • Clustered Infinispan Server deployments, where server instances replicate or distribute data between each other. Clustered deployments provides clients with failover capabilities.

Prerequisites
  • Install Infinispan Server.

Procedure
  1. Create a user

Verification

When you start Infinispan Server check for the following log message:

[org.infinispan.SERVER] ISPN080018: Started connector Resp (internal)

You can now connect to the RESP endpoint with a Redis client. For example, with the Redis CLI you can do the following to add an entry to the cache:

redis-cli -p 11222 --user username --pass password
127.0.0.1:11222> SET k v
OK
127.0.0.1:11222> GET k
"v"
127.0.0.1:11222> quit

1.1. Configuring caches for the RESP endpoint

The RESP endpoint automatically configures and starts a respCache cache. This cache has the following configuration:

  • local-cache or distributed-cache depending on the Infinispan Server clustering mode.

  • application/octet-stream encoding for both keys and values.

  • RESPHashFunctionPartitioner hash partitioner, which supports the CRC16 hashing used by Redis clients

Explicit configuration for cache

It is possible to supply a custom configuration for the cache, as long as it does not violate the requirements of the RESP connector, in which case the server will raise an exception and will not start. Main constraints are:

  • hash partitioning function must be org.infinispan.distribution.ch.impl.RESPHashFunctionPartitioner.

  • key encoding must be application/octet-stream.

Example of explicit cache configuration follows.

XML
<distributed-cache name="respCache" aliases="0" owners="2"
                   key-partitioner="org.infinispan.distribution.ch.impl.RESPHashFunctionPartitioner"
                   mode="SYNC" remote-timeout="17500" statistics="true">
	<encoding media-type="application/octet-stream"/>
</distributed-cache>
JSON
{
   "respCache": {
     "distributed-cache": {
       "aliases": ["0"],
       "owners": "2",
       "key-partitioner": "org.infinispan.distribution.ch.impl.RESPHashFunctionPartitioner",
       "mode": "SYNC",
       "statistics": true,
       "encoding": {
         "media-type": "application/octet-stream"
       }
     }
   }
 }
YAML
respCache:
  distributedCache:
    aliases:
      - "0"
    owners: "2"
    keyPartitioner: "org.infinispan.distribution.ch.impl.RESPHashFunctionPartitioner"
    mode: "SYNC"
    statistics: "true"
    encoding:
      mediaType: "application/octet-stream"

Configure your cache value encoding with Protobuf encoding if you want to view cache entries in the Infinispan Console (value media-type="application/x-protostream").

Explicit RESP endpoint configuration

If the implicit configuration used by the single-port endpoint does not fit your needs, explicit configuration is available.

XML
<endpoints>
  <endpoint socket-binding="default" security-realm="default">
    <resp-connector cache="mycache" />
    <hotrod-connector />
    <rest-connector/>
  </endpoint>
</endpoints>
JSON
{
  "server": {
    "endpoints": {
      "endpoint": {
        "socket-binding": "default",
        "security-realm": "default",
        "resp-connector": {
          "cache": "mycache"
        },
        "hotrod-connector": {},
        "rest-connector": {}
      }
    }
  }
}
YAML
server:
  endpoints:
    endpoint:
      socketBinding: "default"
      securityRealm: "default"
      respConnector:
        cache: "mycache"
      hotrodConnector: ~
      restConnector: ~

2. Mapping caches to Redis logical databases

Use the cache aliases configuration attributes to map caches to Redis logical databases. The default respCache is mapped to logical database 0.

Infinispan can use multiple logical databases even in clustered mode, as opposed to Redis which only supports database 0 when using Redis Cluster.

3. Redis commands

The Infinispan RESP endpoint implements the following Redis commands: