Using Redis to scale Caches, Events, and Queues up and accross Node.js Applications
Ryan-Sandy Lee
Web     ryansandy.com
Github ryan-sandy
var redisDriver = require('redis');
var redis = redisDriver.createClient();
redis.set("forever", "forever-value", function (err) {
redis.get("forever", function (err, val) {
console.log(val);
redis.end();
});
});
forever-value
var redisDriver = require('redis');
var redis = redisDriver.createClient();
redis.setex("expires", 1, "seconds", function (err) {
redis.get("expires", function (err, val) {
console.log(val);
});
setTimeout(function () {
redis.get("expires", function (err, val) {
console.log(val);
redis.end();
});
}, 1500);
});
seconds
null
var redis = require("redis");
var subscriber = redis.createClient();
var publisher = redis.createClient();
subscriber.subscribe("channel 1");
subscriber.subscribe("channel 2");
subscriber.on("message", function (channel, message) {
console.log("message on %s: %s", channel, message);
});
publisher.publish("channel 1", "Hello Edinburgh.js");
publisher.publish("channel 2", "Hello Edinburgh.js");
message on channel 1: Hello Edinburgh.js
message on channel 2: Hello Edinburgh.js
once
instead of on
var queue = require('bull');
var q = queue('simple queue');
q.process(function (job, done) {
console.log(job.data);
done();
});
q.add('a job');
a job