Setup cache¶
The Onegini Extension Engine uses Redis as a cache server to store short-lived values in memory. You can store values within your scripts for later use.
Sentinel is an application that provides high-availability for Redis. The rest of this chapter describes how Redis including Sentinel can be setup and how to configure Redis.
Default cache TTL¶
You can configure the cache TTL with the property REDIS_DEFAULT_TTL_SECONDS
. The default value is 300 seconds (5 minutes).
Example Redis Compose configuration¶
In order to have a high-available Redis setup you must deploy at least 3 Sentinels and 2 Redis nodes (one primary and one replica). You need 3 Sentinels because in case of a failure of the Redis primary, the Sentinels need to elect a new primary. If there are only 2 Sentinels available they cannot get a majority to elect a new primary, and the cluster is in a state with only replica nodes. This means that it will not function anymore.
The code snippet below shows an example Compose configuration that deploys 1 Redis primary, 1 Redis replica and 3 Sentinel nodes.
version: "2"
services:
redis-primary:
image: bitnami/redis:latest
environment:
- ALLOW_EMPTY_PASSWORD=yes
networks:
xe:
ipv4_address: 192.168.0.14
redis-replica:
image: bitnami/redis:latest
environment:
- ALLOW_EMPTY_PASSWORD=yes
- REDIS_MASTER_HOST=redis-primary
- ALLOW_EMPTY_PASSWORD=yes
networks:
xe:
ipv4_address: 192.168.0.15
redis-primary-sentinel:
image: bitnami/redis-sentinel:latest
environment:
- REDIS_MASTER_HOST=redis-primary
depends_on:
- redis-primary
networks:
xe:
ipv4_address: 192.168.0.16
redis-replica-sentinel:
image: bitnami/redis-sentinel:latest
environment:
- REDIS_MASTER_HOST=redis-primary
depends_on:
- redis-primary-sentinel
networks:
xe:
ipv4_address: 192.168.0.17
redis-replica-sentinel-failover:
image: bitnami/redis-sentinel:latest
environment:
- REDIS_MASTER_HOST=redis-primary
depends_on:
- redis-primary-sentinel
networks:
xe:
ipv4_address: 192.168.0.18
networks:
overlay:
driver: bridge
ipam:
config:
- subnet: 192.168.100.0/24
Onegini Extension Engine configuration¶
The Onegini Extension Engine connects to Redis through Sentinel. This means that the Sentinel nodes must be configured in the Extension Engine. Add the following properties to the Extension Engine container environment configuration. The values are inspired on the Redis configuration shown above.
extension-engine::
image: snapshot.onewelcome.com/onegini/extension-engine:latest
restart: always
user: onegini
environment:
...
# Redis
- SPRING_REDIS_SENTINEL_NODES=192.168.0.16:26379,192.168.0.17:26379,192.168.0.18:26379
- SPRING_REDIS_SENTINEL_MASTER=mymaster
...
The SPRING_REDIS_SENTINEL_NODES
are a comma separated list of host:port
pairs that define all sentinel nodes. The SPRING_REDIS_SENTINEL_MASTER
defines the
name of the Redis master. The Onegini Redis container creates a Redis master that is called mymaster
so we need to tell the Extension Engine that our
master is called mymaster
.
A full example of a Extension Engine configuration can be found in the Installation instructions chapter.