https://github.com/cvweiss/redis-websocket
Node implementation of redis to websocket broadcasting.
https://github.com/cvweiss/redis-websocket
nodejs pubsub redis websocket
Last synced: 5 months ago
JSON representation
Node implementation of redis to websocket broadcasting.
- Host: GitHub
- URL: https://github.com/cvweiss/redis-websocket
- Owner: cvweiss
- License: mit
- Created: 2016-07-23T20:40:07.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2025-09-01T22:46:53.000Z (10 months ago)
- Last Synced: 2025-09-02T00:25:13.187Z (10 months ago)
- Topics: nodejs, pubsub, redis, websocket
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# redis-websocket
Creates a websocket on port 15241, listens to all channels on redis, and will publish to each connection the messages from each channel they have subscribed.
To install it:
git clone https://github.com/cvweiss/redis-websocket.git
cd redis-websocket
npm install
To run it:
nodejs app.js
To listen to the public channel, from the browser client connecting to the websocket:
ws.send(JSON.stringify({'action':'sub','channel':'public'}));
Additional channels can be specified one at a time:
ws.send(JSON.stringify({'action':'sub','channel':'datastream'}));
Example:
> nodejs app.js
Sat Jul 23 2016 20:54:15 GMT+0000 (UTC) Server is listening on port 15241
Sat Jul 23 2016 20:54:20 GMT+0000 (UTC) Broadcasted to 72 clients: ping
Sat Jul 23 2016 20:54:40 GMT+0000 (UTC) Broadcasted to 122 clients: pong
Sat Jul 23 2016 20:55:02 GMT+0000 (UTC) Broadcasted to 239 clients: {"action": "test"}
An example of an nginx configuration that listens to port 2096 and passes this to the node app
server {
listen 2096 ssl;
listen [::]:2096 ssl;
server_name wss.example.com;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
location / {
proxy_pass http://127.0.0.1:15241;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
access_log off;
}