Sha256: b02e4d676789235c868f421e89fd45f42a1ed76fe5c0f1b3a08db613ce18a3f8

Contents?: true

Size: 1.3 KB

Versions: 33

Compression:

Stored size: 1.3 KB

Contents

var redis = require("redis"),
    client1 = redis.createClient(), msg_count = 0,
    client2 = redis.createClient();

redis.debug_mode = false;

// Most clients probably don't do much on "subscribe".  This example uses it to coordinate things within one program.
client1.on("subscribe", function (channel, count) {
    console.log("client1 subscribed to " + channel + ", " + count + " total subscriptions");
    if (count === 2) {
        client2.publish("a nice channel", "I am sending a message.");
        client2.publish("another one", "I am sending a second message.");
        client2.publish("a nice channel", "I am sending my last message.");
    }
});

client1.on("unsubscribe", function (channel, count) {
    console.log("client1 unsubscribed from " + channel + ", " + count + " total subscriptions");
    if (count === 0) {
        client2.end();
        client1.end();
    }
});

client1.on("message", function (channel, message) {
    console.log("client1 channel " + channel + ": " + message);
    msg_count += 1;
    if (msg_count === 3) {
        client1.unsubscribe();
    }
});

client1.on("ready", function () {
    // if you need auth, do it here
    client1.incr("did a thing");
    client1.subscribe("a nice channel", "another one");
});

client2.on("ready", function () {
    // if you need auth, do it here
});

Version data entries

33 entries across 33 versions & 4 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/socket.io/node_modules/redis/examples/pub_sub.js
express_translate-1.0.13 node_modules/redis/examples/pub_sub.js
express_translate-1.0.12 node_modules/redis/examples/pub_sub.js
express_translate-1.0.11 node_modules/redis/examples/pub_sub.js