Using the RESP protocol endpoint with Data Grid
Use the Data Grid RESP endpoint to interact with remote caches
Abstract
Red Hat Data Grid
Data Grid is a high-performance, distributed in-memory data store.
- Schemaless data structure
- Flexibility to store different objects as key-value pairs.
- Grid-based data storage
- Designed to distribute and replicate data across clusters.
- Elastic scaling
- Dynamically adjust the number of nodes to meet demand without service disruption.
- Data interoperability
- Store, retrieve, and query data in the grid from different endpoints.
Data Grid documentation
Documentation for Data Grid is available on the Red Hat customer portal.
Data Grid downloads
Access the Data Grid Software Downloads on the Red Hat customer portal.
You must have a Red Hat account to access and download Data Grid software.
Making open source more inclusive
Red Hat is committed to replacing problematic language in our code, documentation, and web properties. We are beginning with these four terms: master, slave, blacklist, and whitelist. Because of the enormity of this endeavor, these changes will be implemented gradually over several upcoming releases. For more details, see our CTO Chris Wright’s message.
1. Data Grid 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 Data Grid Server deployments, exactly like standalone Redis, where each server instance runs independently of each other.
- Clustered Data Grid Server deployments, where server instances replicate or distribute data between each other. Clustered deployments provides clients with failover capabilities.
Prerequisites
- Install Data Grid Server.
Procedure
Verification
When you start Data Grid 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 Data Grid 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 Data Grid 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
.
Data Grid 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 Data Grid RESP endpoint implements the following Redis commands:
- APPEND
- AUTH
- BLPOP
- BLMPOP
- BRPOP
- CLIENT GETNAME
- CLIENT ID
- CLIENT INFO
- CLIENT LIST
- CLIENT SETINFO
- CLIENT SETNAME
- COMMAND
- CONFIG
- CLUSTER KEYSLOT
- Note
This commands includes all required fields, but some fields are set to
0
as they do not apply to Data Grid. - CLUSTER SHARDS
- CLUSTER SLOTS
- DBSIZE
- DECR
- DECRBY
- DEL
- DISCARD
- ECHO
See the MULTI command.
- EXISTS
- EXPIRE
- EXPIREAT
- EXPIRETIME
- Note
This command behaves like
FLUSHDB
since Data Grid does not support multiple Redis databases yet. - FLUSHDB
- GET
- GETDEL
- GETEX
- GETRANGE
- Note
This command is deprecated. Use the
SET
command with the appropriate flags instead. - HDEL
- HELLO
- HEXISTS
- HGET
- HGETALL
- HINCRBY
- HINCRBYFLOAT
- HKEYS
- HLEN
- HMGET
- HMSET
- HRANDFIELD
- HSCAN
- HSET
- HSETNX
- HSTRLEN
- HVALS
- INCR
- INCRBY
- INCRBYFLOAT
- Note
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 Data Grid. - KEYS
- LINDEX
- Note
The current implementation has a time complexity of O(N), where N is the size of the list.
- LLEN
- LCS
- Note
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.
- LMPOP
- LPOP
- LPOS
- LPUSH
- LPUSHX
- LRANGE
- LREM
- LSET
- LTRIM
- Note
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.
- Note
This command will return the same fields as a real Redis server, but all values will be set to
0
. - MGET
- Note
This command always returns an empty list of modules.
- MSET
- MSETNX
- Note
The current implementation has a relaxed isolation level. Redis offers serializable transactions, but Data Grid provides a read-uncommitted isolation.
- PERSIST
- PFADD
- PEXPIRE
- PEXPIREAT
- PEXPIRETIME
- PING
- Note
This command is deprecated. Use the
SET
command with the appropriate flags. - PSUBSCRIBE
- PUBSUB CHANNELS
- PUBSUB NUMPAT
- PTTL
- PUBLISH
- PUNSUBSCRIBE
- QUIT
- RANDOMKEY
- RPOP
- RPOPLPUSH
- RPUSH
- RPUSHX
- READONLY
- READWRITE
- RENAME
- RENAMENX
- RESET
- SADD
- SCARD
- Note
Cursors are reaped in case they have not been used within a timeout. The timeout is 5 minutes.
- SDIFF
- SDIFFSTORE
- Note
Data Grid allows the SELECT command both in local and clustered mode, unlike Redis Cluster which forbids use of this command and only supports database zero.
- SET
- Note
This command is deprecated. Use the
SET
command with the appropriate flags instead. - Note
This command is deprecated. Use the
SET
command with the appropriate flags instead. - SETRANGE
- SINTER
- SINTERCARD
- SINTERSTORE
- SISMEMBER
- SORT
- SORT_RO
- SMEMBERS
- SMISMEMBER
- Note
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.
- SPOP
- SRANDMEMBER
- SREM
- SSCAN
- STRLEN
- Note
This command is deprecated. Use the
GETRANGE
command instead. - SUBSCRIBE
- SUNION
- SUNIONSTORE
- TIME
- TOUCH
- TTL
- TYPE
- UNSUBSCRIBE
- UNWATCH
- WATCH
- ZADD
- ZCARD
- ZCOUNT
- ZDIFF
- ZDIFFSTORE
- ZINCRBY
- ZINTER
- ZINTERCARD
- ZINTERSTORE
- ZLEXCOUNT
- ZMPOP
- ZMSCORE
- ZPOPMAX
- ZPOPMIN
- ZUNION
- ZUNIONSTORE
- ZRANDMEMBER
- ZRANGE
- ZRANGEBYLEX
- ZRANGEBYSCORE
- ZREVRANGE
- ZREVRANGEBYLEX
- ZREVRANGEBYSCORE
- ZRANGESTORE
- ZRANK
- ZREM
- ZREMRANGEBYLEX
- ZREMRANGEBYRANK
- ZREMRANGEBYSCORE
- ZREVRANK
- ZSCAN
- ZSCORE