Question

Can anyone tell me what is wrong with this test code? The program works fine initially but inevitably, I get Redis timeout errors after a few hours of non use. Note, I've changed the redis host and password on this post to false information.

Note, I get the same error, whether I use the node-redis or iris-redis driver.

var express = require('express');
var app = express();

// Redis Data Store
var redis = require("iris-redis");
var client = redis.createClient( 6379, "nodejitsudb5555563948.redis.irstack.com");
client.auth("fehehyrj971946ef332e975fbebb4");

client.on("ready", function() {
  client.iris_config(function(er, config) {
      if(er) throw er;
      console.log("Got my server config: %j", config)
//      client.quit()
  });
});


// Define a test route
app.get('/test', function(req, res) {
  client.incr("seq:test", function(err, reply) {
    console.log("Incremented redis counter: " + reply);
    var body = "Incremented Redis Counter: " + reply;
    res.setHeader('Content-Type', 'text/plain');
    res.setHeader('Content-Length', body.length);
    res.end(body);
  });
});

app.listen(8001);
console.log('Listening on port 8001');
Était-ce utile?

La solution

You probably have timeout not set to 0 on your redis-server. If your application is supposed to be idle for a long period of time, you should have set your timeout to 0. You can check your config file or use the following via redis-cli:

CONFIG GET timeout

If this is already on your production servers and you aren't allowed to put it down for a while, you can do the following to set the redis timeout dynamically using redis-cli:

CONFIG SET timeout 0

Then don't forget to set the following line on your redis config file:

timeout 0
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top