1

谁能告诉我这个测试代码有什么问题?该程序最初运行良好,但不可避免地,在几个小时未使用后,我会收到 Redis 超时错误。请注意,我已将本文中的 redis 主机和密码更改为虚假信息。

请注意,无论我使用 node-redis 还是 iris-redis 驱动程序,我都会遇到同样的错误。

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');
4

1 回答 1

1

你可能还timeout没有0在你的redis-server. 如果您的应用程序应该长时间处于空闲状态,您应该将您的设置timeout0. 您可以检查您的配置文件或通过以下方式使用redis-cli

CONFIG GET timeout

如果这已经在您的生产服务器上并且您暂时不允许将其放下,您可以执行以下操作来timeout动态设置 redis 使用redis-cli

CONFIG SET timeout 0

然后不要忘记在你的 redis 配置文件中设置以下行:

timeout 0
于 2013-11-15T03:11:47.853 回答