Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / redis / examples / pub_sub.js
1 var redis = require("redis"),
2     client1 = redis.createClient(), msg_count = 0,
3     client2 = redis.createClient();
4
5 redis.debug_mode = false;
6
7 // Most clients probably don't do much on "subscribe".  This example uses it to coordinate things within one program.
8 client1.on("subscribe", function (channel, count) {
9     console.log("client1 subscribed to " + channel + ", " + count + " total subscriptions");
10     if (count === 2) {
11         client2.publish("a nice channel", "I am sending a message.");
12         client2.publish("another one", "I am sending a second message.");
13         client2.publish("a nice channel", "I am sending my last message.");
14     }
15 });
16
17 client1.on("unsubscribe", function (channel, count) {
18     console.log("client1 unsubscribed from " + channel + ", " + count + " total subscriptions");
19     if (count === 0) {
20         client2.end();
21         client1.end();
22     }
23 });
24
25 client1.on("message", function (channel, message) {
26     console.log("client1 channel " + channel + ": " + message);
27     msg_count += 1;
28     if (msg_count === 3) {
29         client1.unsubscribe();
30     }
31 });
32
33 client1.on("ready", function () {
34     // if you need auth, do it here
35     client1.incr("did a thing");
36     client1.subscribe("a nice channel", "another one");
37 });
38
39 client2.on("ready", function () {
40     // if you need auth, do it here
41 });