...
 
Commits (5)
0.1.1
- Now using 3rd-Eden/jackpot as connection pool, this should give a more stable
connection.
0.1.0
- Storing numeric values are now returned as numeric values, they are no
longer strings.
0.0.12
- Added .setEncoding to the connections, this way UTF-8 chars will not be
chopped in to multiple pieces and breaking binary stored data or UTF-8 text
0.0.11
- Added more useful error messages instead of returning false. Please note
that they are still strings instead of Error instances (legacy)
0.0.10
- Compatiblity with Node.js 0.8
- Don't saturate the Node process by retrying to connect if pool is full #43
- Minor code formatting
0.0.9
- Codestyle refactor, named the functions, removed tabs
- Added Mocha test suite
......@@ -4,7 +4,6 @@ var EventEmitter = require('events').EventEmitter
, spawn = require('child_process').spawn
, Utils = require('./utils');
exports.Manager = ConnectionManager; // connection pooling
exports.IssueLog = IssueLog; // connection issue handling
exports.Available = ping; // connection availablity
......@@ -104,68 +103,3 @@ issues.attemptReconnect = function attemptReconnect () {
Utils.merge(issue, JSON.parse(JSON.stringify(issue.config)));
});
};
function ConnectionManager (name, limit, constructor) {
this.name = name;
this.total = limit;
this.factory = constructor;
this.connections = [];
}
var Manager = ConnectionManager.prototype;
Manager.allocate = function allocate (callback) {
var total, i
, Manager = this;
i = total = this.connections.length;
// check for available
while (i--){
if (this.isAvailable(this.connections[i])) {
return callback(false, this.connections[i]);
}
}
// create new
if (total < this.total) {
return this.connections.push(this.factory.apply(this, arguments));
}
// give up and don't saturate the node.js process by retying #43
var full = new Error("All the connections in the memcached pool are busy");
full.connectionPool = true;
callback(full);
};
Manager.isAvailable = function isAvailable (connection) {
var readyState = connection.readyState;
return (readyState === 'open' || readyState === 'writeOnly')
&& !(connection._writeQueue && connection._writeQueue.length)
&& !(connection._handle && connection._handle.writeQueueSize);
};
Manager.remove = function remove (connection) {
var position = this.connections.indexOf(connection);
if (position !== -1) this.connections.splice(position, 1);
if (connection.readyState && connection.readyState !== 'closed' && connection.end) {
connection.end();
}
};
Manager.free = function freemymemories (keep) {
var save = 0
, connection;
while (this.connections.length) {
connection = this.connections.shift();
if (save < keep && this.isAvailable(this.connection[0])) {
save++;
continue;
}
this.remove(connection);
}
};
This diff is collapsed.
{
"name": "memcached"
, "version": "0.1.0"
, "version": "0.1.1"
, "author": "Arnout Kazemier"
, "description": "A fully featured Memcached API client, supporting both single and clustered Memcached servers through consistent hashing and failover/failure. Memcached is rewrite of nMemcached, which will be deprecated in the near future."
, "main": "index"
......@@ -34,7 +34,8 @@
, "url" : "http://github.com/3rd-Eden/node-memcached.git"
}
, "dependencies": {
"hashring": "*"
"hashring": "0.0.x"
, "jackpot": "0.0.x"
}
, "devDependencies": {
"mocha": "*"
......