Skip to content

RedisConfig

thiagobustamante edited this page Jul 5, 2017 · 7 revisions

This will configure how the gateway will connect to the Redis database. It is a required configuration in tree-gateway Config File and supports the following properties:

Property Type Description Required
standalone RedisNodeConfig Configure the connection to a standalone Redis. false
sentinel RedisSentinelConfig Configure the connection to Redis using sentinels. false
cluster RedisNodeConfig[] Configure the connection to a redis cluster. false
options RedisOptionsConfig Configure additional options to be passed to redis driver. false

It is important to observe that none of those properties are required, however, you need to specify one (and no more than one) option between standalone, sentinel and cluster.

RedisNodeConfig

Configure a redis node where the gateway will connect.

It support the following properties:

Property Type Description Required
host string The hostname of the redis node. true
port string or number The port of the redis node. false
password string The password to connect on the redis node. false

If none of these are provided, the port 6379 will be used as default.

Example:

 "database": {
    "redis": {
        "standalone": {
            "host": "localhost",
            "port": 6379
        }
    }
}

or

database:
  redis:
    standalone:
      host: "localhost"
      port: 6379

You can write the values for these properties between { and }, to inform to the gateway that an environment variable should be used:

 "database": {
    "redis": {
        "standalone": {
            "host": "{redis_hostname}",
            "port": "{redis_port}"
        }
    }
}

or

database:
  redis:
    standalone:
      host: "{redis_hostname}"
      port: "{redis_port}"

In this example above, the gateway will use an environment variable called redis_hostname to find out the name of the redis host and redis_port as the redis connection port.

RedisSentinelConfig

Configure a redis using sentinels.

It support the following properties:

Property Type Description Required
name string Group os instances to connect (master/slaves group). true
nodes RedisNodeConfig[] List of sentinel nodes. true

Example:

{
    "database": {
        "redis": {
            "sentinel": {
                "name": "redis1",
                "nodes": [
                {
                    "host": "localhost",
                    "port": 6379
                }
                ]
            }
        }
    }
}

or

database:
  redis: 
    sentinel:
      name: redis1
      nodes:
      - host: localhost
        port: 6379

Redis Cluster

Configure a list of start nodes for a redis cluster. You don't need to provide all cluster nodes. The gateway will use this start list and discover the cluster automatically.

Example:

{
    "database": {
        "redis": {
            "cluster": [
                {
                    "host": "host1",
                    "port": 6379
                },
                {
                    "host": "host2",
                    "port": 6379
                }
            ]
        }
    }
}

or

database:
  redis: 
    cluster:
    - host: host1
      port: 6379
    - host: host2
      port: 6379

RedisOptionsConfig

Configure additional options to be passed to redis driver.

It support the following properties:

Property Type Description Required
password string Fallback password. Used when not defined in a node. false
keyPrefix string Prefix to be appended to all keys (defaults to ''). false
connectionName string Connection name, for monitoring purposes. false
db number Database index. false

Example:

{
    "rootPath": ".",
    "database": {
        "redis": {
            "standalone": {
                "host": "{REDIS_PORT_6379_TCP_ADDR}",
                "port": "{REDIS_PORT_6379_TCP_PORT}"
            }, 
            "options": {
                "db": 1
            }
        }
    }
}

or

rootPath: "."
database:
  redis: 
    standalone:
      host: "{REDIS_PORT_6379_TCP_ADDR}"
      port: "{REDIS_PORT_6379_TCP_PORT}"
    options:
      db: 1
Clone this wiki locally