diff --git a/lib/memjs/memjs.js b/lib/memjs/memjs.js index f112736..b8eac35 100644 --- a/lib/memjs/memjs.js +++ b/lib/memjs/memjs.js @@ -86,12 +86,13 @@ Client.create = function(serversStr, options) { Client.prototype.server = function(key) { // TODO(alevy): should use consistent hashing and/or allow swapping hashing // mechanisms - var origIdx = hashCode(key) % this.servers.length; + var total = this.servers.length; + var origIdx = (total > 1) ? (hashCode(key) % total) : 0; var idx = origIdx; var serv = this.servers[idx]; while (serv.wakeupAt && serv.wakeupAt > Date.now()) { - idx = (idx + 1) % this.servers.length; + idx = (idx + 1) % total; if (idx === origIdx) { return null; }