Redis超时错误
任何人都可以告诉我这个testing代码有什么问题吗? 程序工作正常,但不可避免地,我得到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
上可能没有设置为0
timeout
。 如果您的应用程序应该长时间处于空闲状态,则应该将您的timeout
设置为0
。 你可以检查你的configuration文件或通过redis-cli
使用以下命令:
CONFIG GET timeout
如果这已经在您的生产服务器上,并且您不允许放一段时间,您可以执行以下操作,使用redis-cli
dynamic设置redis timeout
:
CONFIG SET timeout 0
那么不要忘了在你的redisconfiguration文件中设置以下行:
timeout 0