aboutsummaryrefslogtreecommitdiffstats
path: root/signaling-server/node_modules/socket.io/node_modules/redis/examples/backpressure_drain.js
blob: 3488ef4d3f712a6b9f2d816dd83bda4b3ed97512 (plain)
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
var redis = require("../index"),
    client = redis.createClient(null, null, {
        command_queue_high_water: 5,
        command_queue_low_water: 1
    }),
    remaining_ops = 100000, paused = false;

function op() {
    if (remaining_ops <= 0) {
        console.error("Finished.");
        process.exit(0);
    }

    remaining_ops--;
    if (client.hset("test hash", "val " + remaining_ops, remaining_ops) === false) {
        console.log("Pausing at " + remaining_ops);
        paused = true;
    } else {
        process.nextTick(op);
    }
}

client.on("drain", function () {
    if (paused) {
        console.log("Resuming at " + remaining_ops);
        paused = false;
        process.nextTick(op);
    } else {
        console.log("Got drain while not paused at " + remaining_ops);
    }
});

op();