-
Notifications
You must be signed in to change notification settings - Fork 0
/
5-publisher.js
23 lines (18 loc) · 707 Bytes
/
5-publisher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { createClient } from 'redis';
const redisClient = createClient();
redisClient.on('connect', function () {
console.log('Redis client connected to the server');
});
redisClient.on('error', function(error) {
console.log(`Redis client not connected to the server: ${error.message}`);
});
function publishMessage(message, time) {
setTimeout(function () {
console.log(`About to send ${message}`);
redisClient.publish('holberton school channel', message);
}, time);
}
publishMessage("Holberton Student #1 starts course", 100);
publishMessage("Holberton Student #2 starts course", 200);
publishMessage("KILL_SERVER", 300);
publishMessage("Holberton Student #3 starts course", 400);