memcache-plus
Advanced tools
Comparing version 0.2.15 to 0.2.16
@@ -115,3 +115,3 @@ | ||
this.buffer = new Immutable.List(); | ||
this.commandBuffer = new Immutable.List(); | ||
@@ -158,6 +158,6 @@ if (opts.onConnect) { | ||
this.buffer.forEach(function(deferred) { | ||
this.commandBuffer.forEach(function(deferred) { | ||
deferred.reject(new Error('Memcache connection lost')); | ||
}); | ||
this.buffer = this.buffer.clear(); | ||
this.commandBuffer = this.commandBuffer.clear(); | ||
}; | ||
@@ -240,6 +240,6 @@ | ||
misc.truncateIfNecessary(data), | ||
this.buffer.size | ||
this.commandBuffer.size | ||
); | ||
var deferred = this.buffer.first(); | ||
var deferred = this.commandBuffer.first(); | ||
@@ -250,3 +250,20 @@ var done = true; | ||
if (data.match(/^ERROR$/) && this.buffer.size > 0) { | ||
if (deferred.type === 'autodiscovery') { | ||
this.autodiscover = this.autodiscover || {}; | ||
done = false; | ||
// Treat this a bit like a special snowflake | ||
if (data.match(/^CONFIG .+/)) { | ||
// Do nothing with this for now | ||
var configItems = data.match(/^CONFIG cluster ([0-9]+) ([0-9]+)/); | ||
this.autodiscover.len = Number(configItems[2]); | ||
} else if (this.autodiscover.len !== undefined && data.match(/^([0-9])+/)) { | ||
this.autodiscover.version = Number(data); | ||
} else if (data.match(/^END$/)) { | ||
resp = this.autodiscover; | ||
this.autodiscover = null; | ||
done = true; | ||
} else if (data.length > 20) { | ||
this.autodiscover.info = data; | ||
} | ||
} else if (data.match(/^ERROR$/) && this.commandBuffer.size > 0) { | ||
debug('got an error from memcached'); | ||
@@ -351,3 +368,3 @@ // We only want to do this if the last thing was not an error, | ||
// Pull this guy off the queue | ||
this.buffer = this.buffer.shift(); | ||
this.commandBuffer = this.commandBuffer.shift(); | ||
// Reset for next loop | ||
@@ -368,3 +385,3 @@ this.data = null; | ||
} | ||
debug('responded and the queue now has "%s" elements', this.buffer.size); | ||
debug('responded and the queue now has "%s" elements', this.commandBuffer.size); | ||
}; | ||
@@ -376,4 +393,5 @@ | ||
Connection.prototype.flushBuffer = function() { | ||
debug('trying to flush buffer for %s', this.host); | ||
if (this.writeBuffer && this.writeBuffer.size > 0) { | ||
debug('flushing connection write buffer'); | ||
debug('flushing write buffer for %s', this.host); | ||
// @todo Watch out for and handle how this behaves with a very long buffer | ||
@@ -385,2 +403,3 @@ while(this.writeBuffer.size > 0) { | ||
} | ||
debug('flushed write buffer for %s', this.host); | ||
} | ||
@@ -405,4 +424,4 @@ }; | ||
} else if (this.writeBuffer.size < this.bufferBeforeError) { | ||
debug('buffering: "%s"', misc.truncateIfNecessary(str)); | ||
this.writeBuffer.push(str); | ||
debug('buffering to [%s]: "%s" ', this.host, misc.truncateIfNecessary(str)); | ||
this.writeBuffer = this.writeBuffer.push(str); | ||
// Check if we should flush this queue. Useful in case it gets stuck for | ||
@@ -414,4 +433,4 @@ // some reason | ||
} else { | ||
this.buffer.first().reject('Error, Connection to memcache lost and buffer over ' + this.bufferBeforeError + ' items'); | ||
this.buffer = this.buffer.shift(); | ||
this.commandBuffer.first().reject('Error, Connection to memcache lost and buffer over ' + this.bufferBeforeError + ' items'); | ||
this.commandBuffer = this.commandBuffer.shift(); | ||
} | ||
@@ -423,12 +442,13 @@ }; | ||
var deferred = misc.defer('autodiscovery'); | ||
this.buffer = this.buffer.push(deferred); | ||
deferred.type = 'autodiscovery'; | ||
this.commandBuffer = this.commandBuffer.push(deferred); | ||
this.write('config get cluster'); | ||
return deferred.promise | ||
.then(function(data) { | ||
debug('got autodiscovery response from elasticache'); | ||
.then(function(config) { | ||
debug('got autodiscovery response from elasticache', config); | ||
// Elasticache returns hosts as a string like the following: | ||
// victor.di6cba.0001.use1.cache.amazonaws.com|10.10.8.18|11211 victor.di6cba.0002.use1.cache.amazonaws.com|10.10.8.133|11211 | ||
// We want to break it into the correct pieces | ||
var hosts = data.toString().split(' '); | ||
var hosts = config.info.toString().split(' '); | ||
return hosts.map(function(host) { | ||
@@ -487,3 +507,3 @@ host = host.split('|'); | ||
deferred.key = key; | ||
this.buffer = this.buffer.push(deferred); | ||
this.commandBuffer = this.commandBuffer.push(deferred); | ||
@@ -531,3 +551,3 @@ // First send the metadata for this request | ||
deferred.type = 'incr'; | ||
this.buffer = this.buffer.push(deferred); | ||
this.commandBuffer = this.commandBuffer.push(deferred); | ||
@@ -557,3 +577,3 @@ this.write(util.format('incr %s %d', key, amount)); | ||
deferred.type = 'decr'; | ||
this.buffer = this.buffer.push(deferred); | ||
this.commandBuffer = this.commandBuffer.push(deferred); | ||
@@ -584,3 +604,3 @@ this.write(util.format('decr %s %d', key, amount)); | ||
var deferred = misc.defer(key); | ||
this.buffer = this.buffer.push(deferred); | ||
this.commandBuffer = this.commandBuffer.push(deferred); | ||
@@ -631,3 +651,3 @@ this.write('get ' + key); | ||
var deferred = misc.defer(delay); | ||
this.buffer = this.buffer.push(deferred); | ||
this.commandBuffer = this.commandBuffer.push(deferred); | ||
@@ -672,3 +692,3 @@ this.write(util.format('flush_all %s', delay)); | ||
deferred.key = key; | ||
this.buffer = this.buffer.push(deferred); | ||
this.commandBuffer = this.commandBuffer.push(deferred); | ||
@@ -724,3 +744,3 @@ // First send the metadata for this request | ||
deferred.key = key; | ||
this.buffer = this.buffer.push(deferred); | ||
this.commandBuffer = this.commandBuffer.push(deferred); | ||
@@ -776,3 +796,3 @@ // First send the metadata for this request | ||
deferred.key = key; | ||
this.buffer = this.buffer.push(deferred); | ||
this.commandBuffer = this.commandBuffer.push(deferred); | ||
@@ -828,3 +848,3 @@ // First send the metadata for this request | ||
deferred.key = key; | ||
this.buffer = this.buffer.push(deferred); | ||
this.commandBuffer = this.commandBuffer.push(deferred); | ||
@@ -859,3 +879,3 @@ // First send the metadata for this request | ||
var deferred = misc.defer(key); | ||
this.buffer = this.buffer.push(deferred); | ||
this.commandBuffer = this.commandBuffer.push(deferred); | ||
@@ -885,3 +905,3 @@ this.write(util.format('delete %s', key)); | ||
this.buffer = this.buffer.push(deferred); | ||
this.commandBuffer = this.commandBuffer.push(deferred); | ||
@@ -921,3 +941,3 @@ this.write(util.format('stats items')); | ||
deferred.type = 'items'; | ||
this.buffer = this.buffer.push(deferred); | ||
this.commandBuffer = this.commandBuffer.push(deferred); | ||
@@ -924,0 +944,0 @@ this.write(util.format('stats cachedump %s %s', slabsId, limit)); |
{ | ||
"name": "memcache-plus", | ||
"version": "0.2.15", | ||
"version": "0.2.16", | ||
"description": "Better memcache for node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -119,7 +119,7 @@ require('chai').should(); | ||
* Ideally one day this can be mocked, but for now just selectively enabling it | ||
it('supports autodiscovery', function(done) { | ||
var cache = new Client({ hosts: ['victor.di6cba.cfg.use1.cache.amazonaws.com'], autodiscover: true }); | ||
it('supports autodiscovery', function() { | ||
var cache = new Client({ hosts: ['test-memcache.di6cba.cfg.use1.cache.amazonaws.com'], autodiscover: true }); | ||
var val = chance.word(); | ||
cache.set('test', val) | ||
return cache.set('test', val) | ||
.then(function() { | ||
@@ -130,3 +130,2 @@ return cache.get('test'); | ||
val.should.equal(v); | ||
done(); | ||
}); | ||
@@ -133,0 +132,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
295673
2421