Last active
December 22, 2020 10:12
-
-
Save RWOverdijk/ac3f8bc1d10b7ec5d864 to your computer and use it in GitHub Desktop.
Enable redis sockets on sails.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.sockets = { | |
// Node.js (and consequently Sails.js) apps scale horizontally. | |
// It's a powerful, efficient approach, but it involves a tiny bit of planning. | |
// At scale, you'll want to be able to copy your app onto multiple Sails.js servers | |
// and throw them behind a load balancer. | |
// | |
// One of the big challenges of scaling an application is that these sorts of clustered | |
// deployments cannot share memory, since they are on physically different machines. | |
// On top of that, there is no guarantee that a user will "stick" with the same server between | |
// requests (whether HTTP or sockets), since the load balancer will route each request to the | |
// Sails server with the most available resources. However that means that all room/pubsub/socket | |
// processing and shared memory has to be offloaded to a shared, remote messaging queue (usually Redis) | |
// | |
// Luckily, Socket.io (and consequently Sails.js) apps support Redis for sockets by default. | |
// To enable a remote redis pubsub server: | |
// adapter: 'redis', | |
// host: '127.0.0.1', | |
// port: 6379, | |
// db: 'sails', | |
// pass: '<redis auth password>' | |
// Worth mentioning is that, if `adapter` config is `redis`, | |
// but host/port is left unset, Sails will try to connect to redis | |
// running on localhost via port 6379 | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.sockets = { | |
adapter: 'redis', | |
host: '127.0.0.1', | |
port: 6379, | |
db: 'sails' | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment