You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-01 16:46:54 +03:00
35 lines
761 B
JavaScript
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();
|