1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-01 16:46:54 +03:00
Files
node-redis/examples/backpressure_drain.js
Ruben Bridgewater 94e9f1fcfc Replace jshint with eslint and add lots of rules
Fix eslint errors accordingly
2016-03-26 14:45:12 +01:00

35 lines
761 B
JavaScript

'use strict';
var redis = require('../index');
var client = redis.createClient();
var remaining_ops = 100000;
var paused = false;
function op () {
if (remaining_ops <= 0) {
console.error('Finished.');
process.exit(0);
}
remaining_ops--;
client.hset('test hash', 'val ' + remaining_ops, remaining_ops);
if (client.should_buffer === true) {
console.log('Pausing at ' + remaining_ops);
paused = true;
} else {
setTimeout(op, 1);
}
}
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();