Last active
May 14, 2018 22:57
-
-
Save rolldone/e461ec950c774f7e5f22ba86e6759461 to your computer and use it in GitHub Desktop.
Create simple app integrated redis with sub pub
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
var NRP = require("node-redis-pubsub"); | |
var config = { | |
host: "localhost", | |
port: 6379, // Port of your locally running Redis server | |
scope: "prerender" // Use a scope to prevent two NRPs from sharing messages | |
}; | |
var nrp = new NRP(config); // This is the NRP client | |
nrp.on("say hello", function(data) { | |
console.log("Hello " + data.name); | |
}); | |
nrp.emit("say hello", { name: "Louis" }); // Outputs 'Hello Louis' | |
// You can use patterns to capture all messages of a certain type | |
// The matched channel is given as a second parameter to the callback | |
nrp.on("city:*", (data, channel) => { | |
console.log(data.city + " is great"); | |
}); | |
nrp.emit("city:hello", { city: "Paris" }); // Outputs 'Paris is great' | |
nrp.emit("city:yeah", { city: "San Francisco" }); // Outputs 'San Francisco is great' |
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
{ | |
"name": "nodejs_redis_integration", | |
"version": "1.0.0", | |
"description": "Create simple app integrated redis with sub pub", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"node-redis-pubsub": "^2.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment