Documentation Documentation

Configure Redis Cluster

Introduction

Our Gateway, Dashboard and Pump all support integration with Redis Cluster. Redis Cluster allows data to be automatically sharded across multiple Redis Nodes. To setup Redis Cluster correctly, we recommend you read the Redis Cluster Tutorial. You must use the same settings across the Gateway, Dashboard and Pump.

NOTE: Redis Cluster is different to a Redis Master/Slave setup.

Redis Cluster & Tyk Gateway

To configure the Tyk Gateway to work with your Redis Cluster, set enable_cluster to true and list your servers under hosts in your tyk.conf file:

	"storage": {
	    "type": "redis",
	    "enable_cluster": true,
	    "hosts" : {
	        "server1": "6379",
	        "server2": "6380",
	        "server3": "6381"
	    },
	    "username": "",
	    "password": "",
	    "database": 0,
	    "optimisation_max_idle": 100
	},

Redis Cluster & Tyk Dashboard

To configure the Tyk Dashboard to work with your Redis Cluster, add the Redis hosts information to your tyk_analytics.conf file:

	"redis_hosts": {
	    "server1": "6379",
	    "server2": "6380",
	    "server3": "6381"
	},
	"enable_cluster": true

Redis Cluster & Tyk Pump

To configure the Tyk Pump to work with your Redis Cluster, set enable_cluster to true and list your servers under hosts in your pump.conf file:

	"analytics_storage_config": {
	    "type": "redis",
	    "enable_cluster": true,
	    "hosts" : {
	        "server1": "6379",
	        "server2": "6380",
	        "server3": "6381"
	    },
	    "username": "",
	    "password": "",
	    "database": 0,
	    "optimisation_max_idle": 100
	},

Then the Cluster driver should be invoked instead of the standard Redis driver.

Redis Cluster with Docker

For Redis clustered mode to work with Tyk using Docker and Amazon ElastiCache, follow these two steps:

Step 1: Make sure cluster mode is enabled

Set the environment variable TYK_GW_STORAGE_ENABLECLUSTER to true.

Step 2: Add all cluster endpoints to the config

Add all the Redis Cluster endpoints into Tyk, not just the primary. If Tyk can’t see the whole cluster, then it will not work.

For ElastiCache Redis, you can bypass having to list all your nodes, and instead just use the configuration endpoint, this allows read and write operations and the endpoint will determine the correct node to target.

If this does not work, you can still list out the hosts using an environment variable. To do so, set the environment variable:

    TYK_GW_STORAGE_HOSTS="redis_master1:port,redis_slave1:port,redis_master2:port,redis_slave2:port,redis_master3:port,redis_slave3:port"

It is important that Tyk can connect to all masters and slaves.

It is recommended to ensure that the connection pool is big enough. To do so, set the following environment variables:

    TYK_GW_STORAGE_MAXIDLE=6000
    TYK_GW_STORAGE_MAXACTIVE=10000

Note: These are suggested settings, please verify them by load testing.

Tyk and Redis Sentinel

We do not support direct integration with Redis Sentinel. You will need to implement it in association with a HAProxy. As we do support Amazon ElastiCache, we recommend using this with Redis Sentinel. For more details on Amazon ElastiCache, see here. The following article also details how to setup Redis Sentinel and HAProxy: Setup Redis Sentinel and HAProxy.