-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question]how to set redis get command timeout #789
Comments
Could you tell me more about your setup and the code that is causing this delay? Is the server remote or local? Is this your first call to Redis in your script after a restart? This is very unusual - Redis usually takes ~1ms to do a simple operation (like |
server is remote, but in the same IDC. Most of the time, it only takes ~1ms, but this >1s situation came about 1time/4-5months, and continue several seconds. i have 4 redis servers, each key will hash to one of them, and then redis.get(This caused delay). |
It's hard to say, but I would venture it is actually not a As far as a timeout, I don't think there is anything in the project to set a specific timeout for a single command. It could be done in your app - perhaps with a closure and a |
I got around to writing a gist on how to do a timeout for a redis command: https://gist.github.com/stockholmux/3a4b2d1480f27df8be67#file-timelimitedredis-js @cekimy Can we close this issue since it's seems more like a redis server stall issue and there is a non-library way of addressing the issue? |
@stockholmux ok, thanks very much, I'll try this gist. |
i still have this problem, when the network between node server and redis server has problem, redis.get will cost hundreds seconds. see our monitor: mostly it takes avg/1ms this is my simple code:
var redis = require("redis"), h = null;
var client = redis.createClient(6379, '10.173.2.22', {enable_offline_queue: false, retry_max_delay: 100});
addListener(client, 'error', null);
addListener(client, 'connect', client);
function addListener(handler, evt, value) {
handler.on(evt, function() {
h = value;
});
}
var puppet = {
'get': function(key, callback) {
if (h === null) {
//reporting error
callback("redis error", null);
} else {
h.get(key, callback);
}
},
//other commands
};
module.exports = puppet;
var http = require('http');
var redis = require("redis.js");
http.createServer(function (req, res) {
//...
var t1 = Date.now();
redis.get('key', function(err, reply) {
var t2 = Date.now();
monitor("time_redis", t2 - t1); //this is reporting to above pic's monitor,calculate the average value
//...
});
//...
}).listen(1337, "10.23.5.42"); |
@cekimy what node_redis version and what parser do you use? |
redis@0.12.1 |
Hm, this is weird. Since you do not use the offline queue. I can't think of a reason why this could happen. Are you certain that you only use .get? Or what commands do you use? |
i use .get, .set, .incr, .hgetall...and so on, but i only monitor the cost of every .get command. |
Hm, you said there were connection issues while the huge delay occured? I can't explain such a delay right now and wonder what happend on your side in this case. And did you try the code from @stockholmux? By having a glimpse at it, it looks good to me for solveing your issue. |
ok,thanks |
Having a command timeout would be a useful feature. I am experiencing an issue where the redis client hangs, after sending a command, for about 15 minutes before the socket emits an I am currently monkey-patching the behavior a la @stockholmux's solution. Ideally I would modify just |
Hi, Can you provide the code sample for lrange+ltrim in multi+exec. Thanks in advance. |
i change the file redis/index.js line 352 |
For those stumbling upon this thread, I ended up using promise-timeout along with the promisified api. Example: const { timeout: promiseTimeout } = require('promise-timeout')
const { promisifyAll } = require('bluebird')
const redis = require('redis')
promisifyAll(redis.RedisClient.prototype)
promisifyAll(redis.Multi.prototype)
const client = redis.createClient({
url: process.env.REDIS_URL
})
const foo = async () => {
const val = await promiseTimeout(client.getAsync(key), REDIS_TIMEOUT)
} |
I've meet a problem several times. redis.get cost much time, more than 1s (even more than 1 minute)
This is a terrible online disaster, so i want to know how to set timeout of get command.
Or what could cause redis cost so much time?
The text was updated successfully, but these errors were encountered: