-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample2.js
More file actions
30 lines (26 loc) · 950 Bytes
/
example2.js
File metadata and controls
30 lines (26 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 192.168.16.13
var http = require("http"),
client = require("redis").createClient();
http.createServer(function (request, response) {
var footer, slide_list, request_count, start = Date.now();
response.writeHead(200, {
"Content-Type": "text/html"
});
client.mget("page_header.html", "page_footer.html", function (err, reply) {
response.write(reply[0]); // header
footer = reply[1].toString();
});
client.hincrby("ip", request.connection.remoteAddress, 1);
client.hgetall("ip", function (err, reply) {
var data = {
ip: {}
};
Object.keys(reply).forEach(function (ip) {
data.ip[ip] = reply[ip].toString();
});
// This is the last reply, so all of the previous replies must have completed
response.write(JSON.stringify(data));
response.write(footer);
response.end();
});
}).listen(9000);