pub Redis lub Nodejs
more example redis pub/sub -> https://github.com/restuwahyu13/express-todo-redis
Restu Wahyu Saputra
more example redis pub/sub -> https://github.com/restuwahyu13/express-todo-redis
1const express = require("express")
2const redis = require("redis")
3
4const publisher = redis.createClient()
5
6const app = express()
7
8app.get("/", (req, res) => {
9 const user = {
10 id: "123456",
11 name: "Davis",
12 }
13
14 publisher.publish("user-notify", JSON.stringify(user))
15 res.send("Publishing an Event using Redis")
16})
17
18app.listen(3005, () => {
19 console.log(`server is listening on PORT 3005`)
20})
var redis = require(“redis”);var subscriber = redis.createClient();subscriber.on(“message”, function (channel, message) { console.log(“Message: “ + message + “ on channel: “ + channel + “ is arrive!”);});subscriber.subscribe(“notification”);