I mainly introduced the use of Nodejs how to read the Memcache sample program, we refer to the use of the bar
The code is as follows: var memcache = require (' memcache ') , HTTP = require (' http ') , url = require (' URL ') &nbs P , QS = require (' querystring ') , memsettings = {port:2000, host: ' 10.6.0.6 '} , Httpse Ttings = {port:3000} , cacheobject = {} , httpserver , client , RequestHandler; client = new Memcache. Client (Memsettings.port, memsettings.host); ... client.on (' Connect ', function () { client.connected = true;}); Client.on (' Close ', function () { //No arguments-connection has been closed Client.conn ected = false; }); function GetData (key, wrapper, Res) { client.get (key, function (error, result) { &N Bsp //All of the callbacks have two arguments. //' result ' may contain things which aren ' t great, but &NBS P   Aren ' t really errors, like ' not_stored ' if (!error) { &NBS P if (result) { cacheobject[ Key] = result; Res.write (wrapper + ' (' + result + ') '); } else { & nbsp Res.write (' no data '); Res.end ( ); { }; /*if (Cacheobject[key]) { Response.Write (Cacheobject[key); Response.End (); } else { client.get (key, function (error, result) { &NB Sp //All of the callbacks have two arguments. //' result ' may contain things which aren ' t great, but &NBS P //aren ' t really errors, like ' not_stored ' if (!error) { &nbs P Cacheobject[key] = result; cacheobject[key][' timeoutid ' = settimeout (function () { &nbs P client.get (key, function (error, result) { &NBS P if (!error) { &NBSP ; Cacheobject[key] = result; & nbsp }); }); Response.Write (result); Response.End (); } } }*/} Httpserver = Http.createserver (function (req, res) { var urlobj, Queryobj; & nbsp Urlobj = Url.parse (Req.url); Res.writehead, {"Content-type": "Text/javascript; Charset=utf-8 "}); Queryobj = Qs.parse (urlobj.query); Path = Queryobj.pathname; if (queryobj.gid) { GetData (Queryobj.gid, queryobj.callback| | Callback ', RES); } else { res.write (' no input '); res.end (); &N Bsp } * switch (urlobj.pathname) { case '/pai ': &N Bsp RES.WRITe (urlobj.pathname); break; case '/qiang ': Res.write (urlobj.pathname); break; default: res.write (' Default '); break; } Res.end (); *}); Client.connect (); Httpserver.listen (Httpsettings.port); Console.log (' HTTP server listening on ' + Httpsettings.port);