forked from Chevrotain/chevrotain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
40 lines (35 loc) · 1.59 KB
/
main.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
const redis = require("redis");
// Creates a new Redis client
// If REDIS_HOST is not set, the default host is localhost
// If REDIS_PORT is not set, the default port is 6379
const redisClient = redis.createClient({
url: `redis://${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`
});
redisClient.on("error", (err) => console.log("Error", err));
(async () => {
await redisClient.connect();
// Sets the key "octocat" to a value of "Mona the octocat"
const setKeyReply = await redisClient.set("octocat", "Mona the Octocat");
console.log("Reply: " + setKeyReply);
// Sets a key to "species", field to "octocat", and "value" to "Cat and Octopus"
const SetFieldOctocatReply = await redisClient.hSet("species", "octocat", "Cat and Octopus");
console.log("Reply: " + SetFieldOctocatReply);
// Sets a key to "species", field to "dinotocat", and "value" to "Dinosaur and Octopus"
const SetFieldDinotocatReply = await redisClient.hSet("species", "dinotocat", "Dinosaur and Octopus");
console.log("Reply: " + SetFieldDinotocatReply);
// Sets a key to "species", field to "robotocat", and "value" to "Cat and Robot"
const SetFieldRobotocatReply = await redisClient.hSet("species", "robotocat", "Cat and Robot");
console.log("Reply: " + SetFieldRobotocatReply);
try {
// Gets all fields in "species" key
const replies = await redisClient.hKeys("species");
console.log(replies.length + " replies:");
replies.forEach((reply, i) => {
console.log(" " + i + ": " + reply);
});
await redisClient.quit();
}
catch (err) {
// statements to handle any exceptions
}
})();