【问题标题】:Redis timeout errorRedis超时错误
【发布时间】:2019-07-03 20:08:06
【问题描述】:

谁能告诉我这个测试代码有什么问题?该程序最初运行良好,但不可避免地,在几个小时未使用后,我会收到 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');

【问题讨论】:

  • 你的 redis 服务器上 CONFIG GET timeout 的输出是什么?

标签: node.js redis node-redis


【解决方案1】:

您的redis-server 上的timeout 可能未设置为0。如果您的应用程序应该长时间处于空闲状态,您应该将您的timeout 设置为0。您可以检查您的配置文件或通过redis-cli 使用以下内容:

CONFIG GET timeout

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

CONFIG SET timeout 0

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

timeout 0

【讨论】:

    猜你喜欢
    • 2013-08-07
    • 2018-01-09
    • 2017-06-28
    • 2023-01-31
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    • 2021-03-16
    • 2015-06-16
    相关资源
    最近更新 更多