We have an API built on Laravel, and we are hoping to add a Redis and Node layer to make it real time compatible, I have a few questions however.
A user/client needs to be subscribe to a channel to see any updates, correct?
All the examples of this method show the channel being hard coded into the node script, obviously are application needs more than 1 channel, of the top of my head, we will need,
User specific notification
My understanding is that if a user subscribes to a channel called 'project' that manages to updates of a project, then if a project name is changed then all projects will be changed to that name? Maybe I wrong.
Any way here is my node script
var https = require('https'), // module for https
fs = require('fs'), // required to read certs and keys
express = require('express');
var options = {
key: fs.readFileSync('ssl/ssl.app.dev.key'),
cert: fs.readFileSync('ssl/ssl.app.dev.crt'),
requestCert: true,
rejectUnauthorized: false
};
var app = express();
var server = https.createServer(options, app);
const redis = require('redis');
const io = require('socket.io');
const client = redis.createClient();
server.listen(3000, 'localhost');
io.listen(server).on('connection', function(client) {
const redisClient = redis.createClient();
var channel;
//console.log(redisClient);
redisClient.subscribe('project_id_64');
redisClient.on("message", function(channel, message) {
//Channel is e.g 'score.update'
console.log("Channel: " + channel);
console.log("Message: " + message);
client.emit(channel, message);
});
client.on('disconnect', function() {
redisClient.quit();
});
});
As you can see I subscribe to redis through a string, is there a way to make this so I can subscribe to redis through variable that can change?