Skip to content

Scale out using redis

Gerasimos (Makis) Maropoulos edited this page Jul 14, 2019 · 1 revision

This section explains aspects of setting up a Redis server for scaling out.

Set up

  1. Download & Run Redis from https://redis.io/download
  2. In the Go import statements add github.com/kataras/neffos/stackexchange/redis and use it.

Use

The first input argument is the optional redis client configuration.

The second one is the redis channel prefix which messages will be published and connections will be subscribed to.

Setting a channel prefix isolates one neffos app from others that use different channel prefixes.

import "github.com/kataras/neffos/stackexchange/redis"

// [server := neffos.New...]

exc, err := redis.NewStackExchange(redis.Config{}, "MyChatApp")
if err != nil {
	// [...]
}
server.UseStackExchange(exc)

Configure options as needed

Options can be set in the Config structure.

Name Description Default
Network Protocol to use "tcp"
Addr Network address of a single redis instance "127.0.0.1:6379"
Clusters A list of network addresses for redis clusters nil
Password A password to connect empty
DialTimeout Max time to connect 0
MaxActive Keep open at least the given number of connections to the redis instance 10

Redis Clustering

Redis Clustering is a method for achieving high availability by using multiple Redis servers. Clustering is supported by the Clusters []string configuration field.

References