Handle error when redis shuts down
See original GitHub issueHello, I have this little node server that communicates with a redis server, I just need some advice how I can make it so the nodejs app doesn’t crash when the redis server goes down. I need it to not crash and try and reconnect to redis, but I am not very experienced with using sockets so I am having quite the trouble, if somebody can help me I would be very greatful!
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var socket = require('socket.io');
var redis = require("redis");
var redisAdapter = require('socket.io-redis');
server.listen(config.nodejs.port, function () {
console.log('listening on ' + config.nodejs.port);
})
var io = socket.listen(server);
io.set("transports", ["xhr-polling", "websocket", "polling", "htmlfile"]);
io.adapter(redisAdapter({host: config.redis.address, port: config.redis.port}));
io.on('connection', function (client) {
console.log('Client connected...');
var sessionId = client.handshake.query.searchSessionId;
client.join(sessionId);
console.log('room ' + sessionId)
});
var searchResultQueue = redis.createClient({host: config.redis.address});
var blpopQueue = function () {
searchResultQueue.blpop('socketio-search-result', 5, function (err, data) {
blpopQueue();
if (data) {
var timestamp = data[1].substring(60, 73);
var eventId = data[1].substring(14, 46);
if (Date.now() - timestamp < searchResultTtl) {
console.log(eventId + ' ' + timestamp)
io.sockets.in(eventId).emit('flights/' + eventId, data[1]);
} else {
console.log(eventId + ' skipped duo expired ttl')
}
}
}
)
}
blpopQueue();
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Handle error when redis shuts down · Issue #301 · socketio ...
I use ioredis as client. I'm listenning on error even of course. It logs the error and then crashes the server.
Read more >Spring Redis Error Handle - Stack Overflow
I had the very same problem. I'm developing some data services against a database, using Redis as the cache store by way of...
Read more >SHUTDOWN - Redis
Since Redis 7.0, the server waits for lagging replicas up to a configurable shutdown-timeout , by default 10 seconds, before shutting down. This...
Read more >Error detection and handling with Redis - IBM Developer
This brings us to error detection and handling with Redis. How can you detect that the Redis server you were connected to has...
Read more >redis server randomly stops without error - Google Groups
I've downgraded redis from 2.8 stable to 2.6 now. Whenever 2.8 crashes it did not delete the pid file however 2.6 deletes the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I resolved this issue using this line: io.of(‘/’).adapter.on(‘error’, function(error){ console.log('error: ', error); });
This still happens for me. I use
ioredis
as client. I’m listenning onerror
even of course. It logs the error and then crashes the server.