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.
-
Install Infinispan Server.
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
ordistributed-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.
<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>
{
"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"
}
}
}
}
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 ( |
Explicit RESP endpoint configuration
If the implicit configuration used by the single-port endpoint does not fit your needs, explicit configuration is available.
<endpoints>
<endpoint socket-binding="default" security-realm="default">
<resp-connector cache="mycache" />
<hotrod-connector />
<rest-connector/>
</endpoint>
</endpoints>
{
"server": {
"endpoints": {
"endpoint": {
"socket-binding": "default",
"security-realm": "default",
"resp-connector": {
"cache": "mycache"
},
"hotrod-connector": {},
"rest-connector": {}
}
}
}
}
server:
endpoints:
endpoint:
socketBinding: "default"
securityRealm: "default"
respConnector:
cache: "mycache"
hotrodConnector: ~
restConnector: ~
Clustered configuration
Infinispan is a horizontally scalable Resp-compatible server with high availability capabilities. Infinispan provides clustering mechanisms with automatic failover detection and membership discovery by default. Topology changes are handled automatically, and adding or removing nodes to the cluster is a streamlined process that automatically redistributes entries between nodes without downtime. The cluster is homogeneous, where nodes are the primary and the backup owners of entries, guaranteeing that entries are available even in case of server failures.
Backed by a consistent hash, compatible with the hash-slot algorithm in Resp clients, entries are distributed across cluster members.
Infinispan automatically redirects requests to the proper entry owner.
As a result, hash tags in keys and the -MOVED
error response for requests are not required even for multi-key operations accessing keys with different owners.
Infinispan allows multiple logical databases with the SELECT command in clustering mode. |
1.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
|
2. Differences between Infinispan and Redis implementation
Infinispan provides different guarantees compared to Redis for some functionalities. This chapter summarizes the differences and, when possible, alternative configurations for a similar behavior.
2.1. Isolation
Redis utilizes a single thread to handle user requests, which provides serializable isolation and atomic behavior for multi-key requests.
Infinispan provides a relaxed isolation level, which is configurable.
Concurrent requests might perceive a partial result for commands that access multiple keys, such as MSET
, where only a subset of the keys were inserted in the cache before the operation finishes.
The only alternative in Infinispan for an atomic behavior is to submit multi-keys operations within a MULTI…EXEC
block.
However, this requires configuring the default cache with transactional capabilities.
Infinispan does not provide serializable transactions. See the cache configuration guide for more information. |
2.2. Transactions
Applications utilizing the MULTI…EXEC
commands should update the default cache configuration to enable transactional capabilities.
Transactions in Redis do not have the concept of rollback to revert in case of failures.
Infinispan provides ACID transactions and rollback in case of failures.
Additionally, the transactions are distributed in cluster mode and can operate across many slots.
The recommended configuration utilizes |
3. Redis commands
The Infinispan RESP endpoint implements the following Redis commands:
-
This commands includes all required fields, but some fields are set to 0
as they do not apply to Infinispan. -
See the MULTI command.
-
This command behaves like FLUSHDB
and flushes only the current database. -
This command is deprecated. Use the SET
command with the appropriate flags instead. -
This implementation attempts to return all attributes that a real Redis server returns. However, in most cases, the values are set to 0
because they cannot be retrieved, or don’t apply to Infinispan. -
The current implementation has a time complexity of O(N), where N is the size of the list. -
The current implementation is atomic for rotation when the source and destination are the same list. For different lists, there is relaxed consistency for concurrent operations or failures unless the resp cache is configured to use transactions. -
This command will return the memory used by the key and the value. It doesn’t include the memory used by additional metadata associated with the entry. -
This command will return the same fields as a real Redis server, but all values will be set to 0
. -
This command always returns an empty list of modules. -
The current implementation has a relaxed isolation level. Redis offers serializable transactions. -
This command is deprecated. Use the SET
command with the appropriate flags. -
Cursors are reaped in case they have not been used within a timeout. The timeout is 5 minutes. -
Infinispan allows the SELECT command both in local and clustered mode, unlike Redis Cluster which forbids use of this command and only supports database zero. -
This command is deprecated. Use the SET
command with the appropriate flags instead. -
This command is deprecated. Use the SET
command with the appropriate flags instead. -
The current implementation has a relaxed isolation level. A client can see the source and destination set without the element. The operation is not atomic, it could remove the element from source and fails to insert to the target set. -
This command is deprecated. Use the GETRANGE
command instead.