Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / redis / examples / web_server.js
1 // A simple web server that generates dyanmic content based on responses from Redis
2
3 var http = require("http"), server,
4     redis_client = require("redis").createClient();
5
6 server = http.createServer(function (request, response) {
7     response.writeHead(200, {
8         "Content-Type": "text/plain"
9     });
10     
11     var redis_info, total_requests;
12     
13     redis_client.info(function (err, reply) {
14         redis_info = reply; // stash response in outer scope
15     });
16     redis_client.incr("requests", function (err, reply) {
17         total_requests = reply; // stash response in outer scope
18     });
19     redis_client.hincrby("ip", request.connection.remoteAddress, 1);
20     redis_client.hgetall("ip", function (err, reply) {
21         // This is the last reply, so all of the previous replies must have completed already
22         response.write("This page was generated after talking to redis.\n\n" +
23             "Redis info:\n" + redis_info + "\n" +
24             "Total requests: " + total_requests + "\n\n" +
25             "IP count: \n");
26         Object.keys(reply).forEach(function (ip) {
27             response.write("    " + ip + ": " + reply[ip] + "\n");
28         });
29         response.end();
30     });
31 }).listen(80);