Geode APIs Compatible with Redis
Note: This feature is experimental and is subject to change in future releases of Apache Geode.
The Geode APIs compatible with Redis allow Geode to function as a drop-in replacement for a highly-available Redis data store, letting Redis applications take advantage of Geode’s scaling capabilities without changing their client code. Redis clients connect to a Geode server in the same way they connect to a Redis server, using a hostname and a port number, with optional password authentication.
Using the Geode APIs Compatible with Redis
The Geode cluster must have at least one server that is set up to handle the incoming Redis commands.
Use gfsh to start at least one server with a command of the form:
start server \
--name=<serverName> \
--locators=<locatorPort> \
--compatible-with-redis-port=<compatibleWithRedisPort> \
--compatible-with-redis-bind-address=<compatibleWithRedisBindAddress> \
--compatible-with-redis-password=<compatibleWithRedisPassword>
If any of the options compatible-with-redis-bind-address
, compatible-with-redis-password
, or compatible-with-redis-port
are included, a Geode server with APIs compatible with Redis will be started.
- Replace
<serverName>
with the name of your server. - Replace
<locatorPort>
with your locator port. - Replace
<compatibleWithRedisPort>
with the port that the Geode server listens on for Redis commands. The typical port used with a cluster compatible with Redis is 6379. - Replace
<compatibleWithRedisBindAddress>
with the address of the server host. - Replace
<compatibleWithWithRedisPassword>
with the password clients use to authenticate.
To confirm the server is listening, run:
redis-cli -h <compatibleWithRedisBindAddress> -p <compatibleWithRedisPort> -a <compatibleWithRedisPassword> ping
Replace <compatibleWithRedisBindAddress>
,<compatibleWithRedisPort>
, and <compatibleWithRedisPassword>
with the same values as the server.
If the server is functioning properly, you should see a response of PONG
.
Supported Redis Commands
The Geode APIs compatible with Redis currently support the following Redis commands.
- APPEND
- AUTH
- DECR
- DECRBY
- DEL
- EXISTS
- EXPIRE
- EXPIREAT
- GET
- GETRANGE
- HDEL
- HEXISTS
- HGET
- HGETALL
- HINCRBY
- HINCRBYFLOAT
- HLEN
- HMGET
- HMSET
- HSCAN [1]
- HSET
- HSETNX
- HSTRLEN
- HVALS
- HKEYS
- INCR
- INCRBY
- INCRBYFLOAT
- INFO [2]
- KEYS
- MGET
- PERSIST
- PEXPIRE
- PEXPIREAT
- PING
- PSUBSCRIBE
- PTTL
- PUBLISH
- PUNSUBSCRIBE
- QUIT
- RENAME
- SADD
- SET
- SETNX
- SLOWLOG [3]
- SMEMBERS
- SREM
- STRLEN
- SUBSCRIBE
- TTL
- TYPE
- UNSUBSCRIBE
Commands not listed above are not implemented.
NOTES:
These commands are supported for Redis 5.
[1] Redis accepts 64-bit signed integers for the HSCAN cursor and COUNT parameters. The Geode APIs compatible with Redis are limited to 32-bit integer values for these parameters.
[2] INFO is implemented for the sections and fields listed below:
- server
- redis_version
- redis_mode (always returns “standalone”)
- tcp_port
- uptime_in_seconds
- uptime_in_days
- clients
- connected_clients
- blocked_clients (always returns 0)
- memory
- maxmemory
- used_memory
- mem_fragmentation_ratio (always reports 1.00)
- persistence
- loading (always returns 0)
- rdb_changes_since_last_save (always returns 0)
- rdb_last_save_time (always returns 0)
- stats
- total_commands_processed
- instantaneous_ops_per_sec
- total_net_input_bytes
- instantaneous_input_kbps
- total_connections_received
- keyspace_hits
- keyspace_misses
- evicted_keys (always returns 0)
- rejected_connections (always returns 0)
- keyspace
- returns stats for db: 0
- keys (returns num keys)
- expires (always returns 0)
- avg_ttl (always returns 0)
- returns stats for db: 0
- replication
- role (always returns “master”)
- connected_slaves (always returns 0)
- cluster
- cluster_enabled (always returns 0)
[3] SLOWLOG is implemented as a NoOp.
Advantages of Geode over Redis
Geode’s primary advantage is its scalability. While the Redis server is single threaded, Geode supports high concurrency. Many Redis clients can execute commands on the Geode cluster simultaneously.
Geode’s architecture and management features help detect and resolve network partitioning problems without explicit management on the part of the Redis client.
Expiration Accuracy
Keys are expired in two ways, actively and passively:
- With passive expiration, expiration is evaluated whenever a key is accessed. If the key is due to expire, it is deleted.
- With active expiration, keys are evaluated every 3 minutes. If they are due to expire, they are deleted.
High Availability Model
Data is stored in a single partitioned region that has one redundant copy. In practice this means that the cluster can tolerate the loss of a single server without the loss of data.
Loss of Connections
There are a number of events that might occur within the Geode cluster that can result in the cluster closing the connection to the Redis client. Losing the connection to the cluster does not imply that the server is no longer available.
When the connection is lost, the client should attempt to reconnect to the same server before attempting to connect to another server. The Redis client is responsible for knowing the addresses of all servers.
In the case of a connection failure, an invoked command may or may not complete. The Redis client is responsible for deciding if the command should be retried.