1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00
Files
node-redis/examples/backpressure_drain.js
Ruben Bridgewater 1f9e536ca0 Add use strict statements
This is going to improve the performance minimal and improves the safety of the code
2015-07-22 17:50:37 +02:00

36 lines
825 B
JavaScript

'use strict';
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();