-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (36 loc) · 1.08 KB
/
server.js
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
31
32
33
34
35
36
37
38
39
40
41
42
const http = require('http');
const keys = require('./keys');
const redis = require('redis');
// const client = redis.createClient(); // this creates a new client
const client = redis.createClient(
keys.redisPort,
keys.redisHost
);
isRedisConnected = false;
var handleRequest = function(request, response) {
console.log('Received request for URL: ' + request.url);
response.writeHead(200);
client.get('mkey', function (error, result) {
if (error) {
console.log(error);
throw error;
isRedisConnected = false;
}
console.log('REDIS GET result ->' + result);
});
var str = "REDIS IS ALSO CONNECTED."
if(!isRedisConnected){
str = "REDIS NOT CONNECTED.";
}
response.end('Hello k8s World! This is Node running on GKE.\n\n' + str);
};
var www = http.createServer(handleRequest);
www.listen(8086);
client.on('connect', function() {
console.log('Redis client connected');
isRedisConnected = true;
client.set('mkey', 'my_test_value', redis.print);
});
client.on('error', function (err) {
console.log('Something went wrong ' + err);
});