index.js
/**
 * HashRing implements consistent hashing so adding or removing servers of one
 * slot does not significantly change the mapping of the key to slots. The
 * consistent hashing algorithm is based on ketama or libketama.
 *
 * @constructor
 * @param {Mixed} server Servers that need to be added to the ring.
 * @param {Mixed} algorithm Either a Crypto compatible algorithm or custom hasher.
 * @param {Object} options Optional configuration and options for the ring.
 * @api public
 */
HashRing implements consistent hashing so adding or removing servers of one
slot does not significantly change the mapping of the key to slots. The
consistent hashing algorithm is based on ketama or libketama.

@constructor
@param {Mixed} server Servers that need to be added to the ring.
@param {Mixed} algorithm Either a Crypto compatible algorithm or custom hasher.
@param {Object} options Optional configuration and options for the ring.
@api public
HashRing implements consistent hashing so adding or removing servers of one slot does not significantly change the mapping of the key to slots . The consistent hashing algorithm is based on ketama or libketama . @constructor @param { Mixed } server Servers that need to be added to the ring . @param { Mixed } algorithm Either a Crypto compatible algorithm or custom hasher . @param { Object } options Optional configuration and options for the ring . @api public
function HashRing(servers, algorithm, options) {
  options = options || {};
   These properties can be configured
  this.vnode = 'vnode count' in options ? options['vnode count'] : 40;
  this.algorithm = algorithm || 'md5';
   If the default port is set, and a host uses it, then it is excluded from
   the hash.
  this.defaultport = options['default port'] || null;
   There's a slight difference between libketama and python's hash_ring
   module, libketama creates 160 points per server:
     40 hashes (vnodes) and 4 replicas per hash = 160 points per server.
   The hash_ring module only uses 120 points per server:
     40 hashes (vnodes) and 3 replicas per hash = 120 points per server.
   And that's the only difference between the original ketama hash and the
   hash_ring package. Small, but important.
  this.replicas = options.compatibility
    ? (options.compatibility === 'hash_ring' ? 3 : 4)
    : ('replicas' in options ? +options.replicas : 4);
   Replicas cannot be 0 as it means we have nothing to iterate over when
   creating the initial hash ring.
  if (this.replicas <= 0) this.replicas = 1;
   Private properties.
  var connections = parse(servers);
  this.ring = [];
  this.size = 0;
  this.vnodes = connections.vnodes;
  this.servers = connections.servers;
   Set up a cache as we don't want to preform a hashing operation every single
   time we lookup a key.
  this.cache = new SimpleCache({
    maxSize: 'max cache size' in  options ? options['max cache size'] : 5000
  });
   Override the hashing function if people want to use a hashing algorithm
   that is not supported by Node, for example if you want to MurMur hashing or
   something else exotic.
  if ('function' === typeof this.algorithm) {
    this.hash = this.algorithm;
  }
   Generate the continuum of the HashRing.
  this.continuum();
}
function HashRing ( servers , algorithm , options ) { options = options || { } ; this . vnode = 'vnode count' in options ? options [ 'vnode count' ] : 40 ; this . algorithm = algorithm || 'md5' ; this . defaultport = options [ 'default port' ] || null ; this . replicas = options . compatibility ? ( options . compatibility === 'hash_ring' ? 3 : 4 ) : ( 'replicas' in options ? + options . replicas : 4 ) ; if ( this . replicas <= 0 ) this . replicas = 1 ; var connections = parse ( servers ) ; this . ring = [ ] ; this . size = 0 ; this . vnodes = connections . vnodes ; this . servers = connections . servers ; this . cache = new SimpleCache ( { maxSize : 'max cache size' in options ? options [ 'max cache size' ] : 5000 } ) ; if ( 'function' === typeof this . algorithm ) { this . hash = this . algorithm ; } this . continuum ( ) ; }
HashRing implements consistent hashing so adding or removing servers of one
 slot does not significantly change the mapping of the key to slots.
HashRing implements consistent hashing so adding or removing servers of one slot does not significantly change the mapping of the key to slots .
// // These properties can be configured // // // If the default port is set, and a host uses it, then it is excluded from // the hash. // // // There's a slight difference between libketama and python's hash_ring // module, libketama creates 160 points per server: // //   40 hashes (vnodes) and 4 replicas per hash = 160 points per server. // // The hash_ring module only uses 120 points per server: // //   40 hashes (vnodes) and 3 replicas per hash = 120 points per server. // // And that's the only difference between the original ketama hash and the // hash_ring package. Small, but important. // // // Replicas cannot be 0 as it means we have nothing to iterate over when // creating the initial hash ring. // // Private properties. // Set up a cache as we don't want to preform a hashing operation every single // time we lookup a key. // Override the hashing function if people want to use a hashing algorithm // that is not supported by Node, for example if you want to MurMur hashing or // something else exotic. // Generate the continuum of the HashRing.