Skip to content

gravitee-io/gravitee-resource-cache-redis

Repository files navigation

Redis Cache Resource

Gravitee.io License Releases CircleCI Join the community forum

Description

The Redis cache resource is used to maintain a cache and link it to the API lifecycle. It means that the cache is initialized when the API is starting and released when API is stopped.

This cache is responsible to store HTTP response from the backend to avoid subsequent calls.

Current implementation of the cache resource is based on Redis.

Compatibility with APIM

Plugin version APIM version

4.0

4.6 to latest

3.0

DO NOT USE

2.0

4.5 to latest

1.5

4.0 to 4.4

Configuration

You can configure the resource with the following options :

Property Required Description Type Default EL Support Secret Support

name

X

The name of the cache.

string

my-redis-cache

X

-

releaseCache

X

Release the cache when API is stopped? If enabled, the resource will release the cache. If not, you will have to manage it by yourself on your Redis server.

boolean

false

-

-

maxTotal

X

The maximum number of connections that are supported by the pool.

integer

8

-

-

password

The password of the instance.

string

X

X

timeToLiveSeconds

X

The maximum number of seconds an element can exist in the cache regardless of use. The element expires at this limit and will no longer be returned from the cache. The default value is 0, which means no timeToLive (TTL) eviction takes place (infinite lifetime).

integer

0

-

-

timeout

X

The timeout parameter specifies the connection timeout and the read/write timeout.

integer

2000

-

-

useSsl

X

Use SSL connections.

boolean

true

-

-

sentinelMode

X

Sentinel provides high availability for Redis. In practical terms this means that using Sentinel you can create a Redis deployment that resists without human intervention certain kinds of failures.

boolean

false

-

-

Standalone configuration

Property Required Description Type Default EL Support Secret Support

host

X

The host of the instance

string

localhost

X

-

port

X

The port of the instance.

integer

6379

-

-

Configuration example
{
    "name" : "my-redis-cache",
    "type" : "cache-redis",
    "enabled" : true,
    "configuration" : {
        "name" : "my-redis-cache",
        "releaseCache": false,
        "maxTotal" : 8,
        "password" : "secret",
        "timeToLiveSeconds" : 600,
        "timeout" : 2000,
        "useSsl" : true,
        "sentinelMode" : false,
        "standalone": {
            "host" : "localhost",
            "port" : 6379
        }
    }
}
Extract with a secret and EL
{
    "enabled" : true,
    "configuration" : {
        "password" : "{#secrets.get('/kubernetes/redis:password')}",
        "standalone": {
            "host" : "{#dictionary['redis']['host']}",
            "port" : 6379
        }
    }
}

Sentinel configuration

Property Required Description Type Default EL Support Secret Support

masterId

X

The sentinel master id

string

sentinel-master

X

-

password

-

The sentinel password.

string

X

X

nodes

X

List of sentinel nodes.

Array

-

-

Configuration example
{
    "name" : "my-redis-cache",
    "type" : "cache-redis",
    "enabled" : true,
    "configuration" : {
        "name" : "my-redis-cache",
        "releaseCache": false,
        "maxTotal" : 8,
        "password" : "secret",
        "timeToLiveSeconds" : 600,
        "timeout" : 2000,
        "useSsl" : true,
        "sentinelMode" : true,
        "sentinel" : {
            "masterId" : "sentinel-master",
            "password" : "secret",
            "nodes": [
              {
                "host" : "localhost",
                "port" : 26379
              },
              {
                "host" : "localhost",
                "port" : 26380
              },
              {
                "host" : "localhost",
                "port" : 26381
              }
            ]
        }
    }
}