Skip to content

takayukii/example-socket.io-emitter-redis

Repository files navigation

Example: Notification from backend with Socket.io and Redis

This sample is demonstrating sending events via socket, which coming from where isn't Socket.io context. e.g. database, batch, etc. To send those events to browsers via socket, it can be achieved with socket.io-emitter. Also, I combined this sample with Redis to proof scalability.

Prerequisites

Docker for Mac/Windows, etc. I'm using docker-compose.

Set up

Running Redis

$ docker-compose up

If you want to stop docker, just hit Ctrl+C.

Quick redis-cli memo.

$ redis-cli # connect to redis
$ > flushall # delete all
$ > keys * # check all keys
$ > get <key> # get value

You can install redis-cli via brew install redis.

Install dependencies

$ npm install

Build client's source codes

$ npm run build

Demo

Run server with port 3000

$ node index.js 3000

Run server with port 4000

$ node index.js 4000

You can send message to specific users.

Remarks

If you're interested in case of separated socket.io server. I've prepared demo for that case too, on different branch.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published