gpt4 book ai didi

node.js - Redis 超时错误

转载 作者:IT王子 更新时间:2023-10-29 06:15:41 24 4
gpt4 key购买 nike

谁能告诉我这个测试代码有什么问题?该程序最初运行良好,但不可避免地,在几个小时未使用后我会收到 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-server 上的 timeout 可能未设置为 0。如果您的应用程序应该长时间处于空闲状态,您应该将 timeout 设置为 0。您可以检查您的配置文件或通过 redis-cli 使用以下内容:

CONFIG GET timeout

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

CONFIG SET timeout 0

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

timeout 0

关于node.js - Redis 超时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19008145/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com