首頁 >web前端 >js教程 >nodejs讀取memcache範例分享_javascript技巧

nodejs讀取memcache範例分享_javascript技巧

WBOY
WBOY原創
2016-05-16 17:05:421032瀏覽

複製程式碼 程式碼如下:

var memcache = require('memcache')
    , http = require('http')
    , url = require('url')
    , url = require('url')
    , url = require('url')
    , url = require('url')
   )
    , memsettings = { 連接埠: 2000, 主機: '10.6.0.6' }
    , httpsettings = {Object: 3000 }    , requestHandler;

client = new memcache.Client(memsettings.port, memsettings.host);
//...
client.on('connect', ftionunc() {
    client.connected = true;
});

client.on('close', function(){
   connected = false;
});

function getData(key,wrapper,res){
    client.get(key,function(error, 兩個參數。 if(!error){
if(結果){
                    cacheObject[key] = result;
    🎜>                } else {
             🎜>                }
                   });
    /*if(cacheObject[key]){
        res ponse.write(cacheObject[key]);
        response.end();
    } else  {
           // 所有回呼都有兩個參數。
// 'result' 可能包含不太好的內容,但是
            /// 上真正的錯誤,例如'NOT_STORED'               cacheObject[key]['timeoutId'] = setTimeout(function(){
   ult){
                       if(!error){
   cacheObject[有效性] = 結果;
                        }
                });
                所  🎜>            }
        });
    }*/
}

httpserver = http.createServer(function(req, res){
    var urlObj, queryObj;
    urlObj = .url.parIf.url {"Content-Type":"text/javascript; charset=utf-8"});
    queryObj = qs.parse(urlObj.query);
    路徑) ) .gid){
        getData(queryObj.gid, queryObj.callback||'callback', res);
          res . end ();
    }
    /*
    switch(urlObj.name){
    res.write(urlObj.pathname);
        break;
        case '/qiang':
            res.write(urlObj.pathname);            res.write('default');
        休息;
}
    res.end();
    */
});

client.connect();
httpserver.listen(httpsettings.port);
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn