| 1 |
In this example we show how to connect several Centrifuge server nodes with Redis – thus making it possible to scale nodes. |
| 2 |
|
| 3 |
Start 2 Redis servers locally (we could use just one actually, but here we show builtin Redis sharding feature): |
| 4 |
|
| 5 |
``` |
| 6 |
redis-server --port 6379 |
| 7 |
``` |
| 8 |
|
| 9 |
And another one on port `6380`: |
| 10 |
|
| 11 |
``` |
| 12 |
redis-server --port 6380 |
| 13 |
``` |
| 14 |
|
| 15 |
Then start 2 instances of this app on different ports: |
| 16 |
|
| 17 |
``` |
| 18 |
go run main.go -port 8000 |
| 19 |
``` |
| 20 |
|
| 21 |
And: |
| 22 |
|
| 23 |
``` |
| 24 |
go run main.go -port 8001 |
| 25 |
``` |
| 26 |
|
| 27 |
Then go to http://localhost:8000 and to http://localhost:8001 in another browser tab. You will see simple chat app in both browser tabs, try writing a chat message in one browser tab – you should see it appears in another tab. |
| 28 |
|
| 29 |
This example uses two Redis instances so published messages will be automatically sharded among them (consistently sharded by a channel). |