首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Redis回调中使用node.js http代理

在Redis回调中使用node.js http代理
EN

Stack Overflow用户
提问于 2012-04-16 08:33:08
回答 1查看 865关注 0票数 1

考虑到这个不完整的代码片段:

代码语言:javascript
复制
var util = require('util'),
    nconf = require('nconf'),

    http = require('http'),
    httpProxy = require('http-proxy'),

    express = require('express'),
    repoServer = express.createServer(),

    redis = require('redis'),
    redisClient = redis.createClient();

// (...)

var proxy = new httpProxy.RoutingProxy();
http.createServer(function (req, res) {
  console.log("URL", req.url);
  if (req.url) {
    var token = req.url.split("/")[1];

    // if I leave this code here it works fine
    // var target = { host: 'local-01', port: 8024 }
    // proxy.proxyRequest(req, res, target);

    // now I need to retrieve some routing information
    // from redis, so I query redis here
    redisClient.get(token, function (err, reply) {
      // if I leave this code here the request hangs
      var target = { host: 'local-01', port: 8024 }
      proxy.proxyRequest(req, res, target);
    });
  }
}).listen(routerInfo.port, routerInfo.address);

为什么当我在de redis客户端get回调之外调用HTTP时,它可以正常工作,但当我将调用移到回调内时,它会失败,HTTP请求就会挂起?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-16 08:45:36

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10167431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档