forked from bnusunny/supersonic-java-on-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (28 loc) · 858 Bytes
/
index.js
File metadata and controls
40 lines (28 loc) · 858 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
31
32
33
34
35
36
37
38
39
40
const redis = require("redis");
const redis_url = `redis://${process.env.REDIS_HOST}:6379/0` || "redis://localhost:6379/0"
console.log(`redis url is ${redis_url}`);
module.exports.handler = (event, context, callback) => {
console.log("handler begin");
const client = redis.createClient(redis_url);
client.set("nodejs", "hello world", (err, data) => {
client.quit();
console.log(`callback begin. err= ${err}, data=${data}`);
if (err) {
const response = {
statusCode: 500,
body: JSON.stringify({
message: "write to redis failed\n",
}),
};
callback(null, response);
} else {
const response = {
statusCode: 200,
body: JSON.stringify({
message: "data is writen to redis\n",
}),
};
callback(null, response);
}
});
};