You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
fix for buffered_writes -- now drain event works
This commit is contained in:
2
index.js
2
index.js
@@ -286,7 +286,7 @@ RedisClient.prototype.send_offline_queue = function () {
|
|||||||
this.offline_queue = new Queue();
|
this.offline_queue = new Queue();
|
||||||
// Even though items were shifted off, Queue backing store still uses memory until next add, so just get a new Queue
|
// Even though items were shifted off, Queue backing store still uses memory until next add, so just get a new Queue
|
||||||
|
|
||||||
if (buffered_writes === 0) {
|
if (!buffered_writes) {
|
||||||
this.should_buffer = false;
|
this.should_buffer = false;
|
||||||
this.emit("drain");
|
this.emit("drain");
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,33 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var freemem = require('os').freemem;
|
||||||
var codec = require('../codec');
|
var codec = require('../codec');
|
||||||
|
|
||||||
var pub = require('redis').createClient()
|
var sent = 0;
|
||||||
.on('ready', function() {
|
|
||||||
while (true) {
|
var pub = require('redis').createClient(null, null, {
|
||||||
pub.publish('timeline', codec.encode({
|
command_queue_high_water: 5,
|
||||||
cmd: Math.random(),
|
command_queue_low_water: 1
|
||||||
data: Math.random()
|
})
|
||||||
}));
|
.on('ready', function() {
|
||||||
}
|
this.emit('drain');
|
||||||
});
|
})
|
||||||
|
.on('drain', function() {
|
||||||
|
process.nextTick(exec);
|
||||||
|
});
|
||||||
|
|
||||||
|
var payload = '1'; for (var i = 0; i < 10; ++i) payload += payload;
|
||||||
|
|
||||||
|
function exec() {
|
||||||
|
pub.publish('timeline', codec.encode({ foo: payload }));
|
||||||
|
++sent;
|
||||||
|
if (!pub.should_buffer) {
|
||||||
|
process.nextTick(exec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exec();
|
||||||
|
|
||||||
|
setInterval(function() {
|
||||||
|
console.log('sent', sent, 'free', freemem(), 'cmdqlen', pub.command_queue.length, 'offqlen', pub.offline_queue.length);
|
||||||
|
}, 1000);
|
||||||
|
Reference in New Issue
Block a user