任何redis调用的ioredis发送命令的默认超时时间是多少 [英] What's the default timeout of ioredis send command for any redis call

查看:126
本文介绍了任何redis调用的ioredis发送命令的默认超时时间是多少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有节点应用程序的 ioredis,由于集群中的一些问题,我开始得到:

I am using ioredis with a node application, and due to some issues at cluster I started getting:

集群重定向过多.最后一个错误:错误:连接已关闭.

Too many Cluster redirections. Last error: Error: Connection is closed.

由于这个原因,我所有的 redis 调用都失败了,并且在 1 秒到 130 秒的很长时间之后.

Due to which all of my redis calls failed and after a very long time ranging from 1sec to 130secs.

ioredis 库是否有任何默认超时,它用于在发送命令以执行到 redis 服务器后断言调用?

Is there any default timeout for ioredis library which it uses to assert the call after sending command to execute to redis server?

向redis服务器发送命令的失败时间更长,范围为100秒,是因为集群失败导致redis的队列大小过高吗?

Higher failure time of range 100secs on sending commands to redis server, is it because the the high queue size at redis due to cluster failure?

示例代码:

this.getData = function(bucketName, userKey) {
  let cacheKey = cacheHelper.formCacheKey(userKey, bucketName);
  let serviceType = cacheHelper.getServiceType(bucketName, cacheConfig.service_config);
  let log_info = _.get(cacheConfig.service_config, 'logging_options.cache_info_level', true);
  let startTime = moment();
  let dataLength = null;
  return Promise.try(function(){
    validations([cacheKey], ['cache_key'], bucketName, serviceType, that.currentService);
    return cacheStore.get(serviceType, cacheKey);
  })
  .then(function(data) {
    dataLength = (data || '').length;
    return cacheHelper.uncompress(data);
  })
  .then(function(uncompressedData) {
    let endTime = moment();
    let responseTime = endTime.diff(startTime, 'miliseconds');
    if(!uncompressedData) {
      if(log_info) logger.consoleLog(bucketName, 'getData', 'miss', cacheKey, that.currentService,
        responseTime, dataLength);
    } else {
      if(log_info) logger.consoleLog(bucketName, 'getData', 'success', cacheKey, that.currentService,
        responseTime, dataLength);
    }
    return uncompressedData;
  })
  .catch(function(err) {
    let endTime = moment();
    let responseTime = endTime.diff(startTime, 'miliseconds');
    logger.error(bucketName, 'getData', err.message, userKey, that.currentService, responseTime);
    throw cacheResponse.error(err);
  });
};

这里logger.error(bucketName, 'getData', err.message, userKey, that.currentService, responseTime);

开始给出范围为 1061ms 到 109939ms 的响应时间.

started giving response time of range 1061ms to 109939ms.

请提供一些意见.

推荐答案

正如你可以从这个ioredis 问题,没有每个命令的超时配置.

As you can read from this ioredis issue, there isn't a per-command timeout configuration.

正如链接评论中所建议的,您可以使用基于 Promise 的策略作为解决方法.顺便说一句,这与 ioredis-timeout 插件 使用的策略相同,它将原始命令包装在a Promise.race() 方法:

As suggested in the linked comment, you can use a Promise-based strategy as a workaround. Incidentally, this is the same strategy used by the ioredis-timeout plugin that wraps the original command in a Promise.race() method:

//code from the ioredis-timeout lib
return Promise.race([
      promiseDelay(ms, command, args),
      originCommand.apply(redis, args)
]);

所以你可以使用插件或这个不错的race超时技术来添加超时redis 客户端之上的功能.请记住,底层命令不会被中断.

So you can use the plugin or this nice race timeout technique to add a timeout functionality on top of the redis client. Keep in mind that the underlying command will not be interrupted.

这篇关于任何redis调用的ioredis发送命令的默认超时时间是多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆