npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fast-redis-cluster2

v2.0.13

Published

Fast trully async redis cluster client library with HA support, can handle reshard, failovers etc...

Downloads

33

Readme

Fast-redis-cluster2

Absolutely new driver which designed for high performance and proper handling of cluster resize, failover, utf-8 keys and cluster hashtags.

Benchmark (2021 september)

134263496-d43faa0d-4740-4cc4-bfcd-daebd17c7138

Installation

npm install fast-redis-cluster2 --save

Usage

Check example.js or spec folder for more information.

var redisCluser = require('fast-redis-cluster2').clusterClient;

var opts = {
	//`host` can be ip/hostname of any working instance of cluster
	host: '127.0.0.1',
	port: 7001,
	// auth: 'topsecretpassword',
	// force to use fallback node_redis driver as connector
	// useFallbackDriver: true,
};
//or you can set there just a string
//var opts = '127.0.0.1:7001';

var redis = new redisCluser.clusterInstance(opts, function (err) {
	if (err) throw new Error(err);
	console.log('Connected, cluster is fine and ready for using');
});

redis.on('ready', function(){
	console.log('Connected, cluster is fine and ready for using');
});

redis.on('error', function(err){
	console.log('Redis error', err);
});

//each redis command executed before a `ready` event will be queued and processed in right order when `ready` is occured
//callback is optional and if it exists it must be placed as a last argument
redis.set('foo', 'bar2', function(err, resp){
	console.log('set command returns err: %s, resp: %s', err, resp);
});

//callback is optional
redis.set('foo', 'bar3');

redis.get('foo', function(err, resp){
	console.log('get foo command returns err: %s, resp: %s', err, resp);
});

//internally the library uses a rawCall function
//for higher performance better to use rawCall function directly
//rawCall function has 2 arguments,
//1 - array which contain a redis command
//2 - optional callback
//Redis command is case insesitive, e.g. you can specify HMGET as HMGET, hmget or HmGeT
//but keys and value are case sensitive, foo and Foo not the same...
redis.rawCall(['set', 'foo', 'bar'], function(err, resp){
	console.log('SET via rawCall command returns err: %s, resp: %s', err, resp);
});

//types are decoded exactly as redis returns it
//e.g. GET will return string
redis.rawCall(['set', 'number', 123]);
redis.rawCall(['get', 'number'], function(err, resp){
	//type of "resp" will be "string"
	//this is not related to driver this is behaviour of redis...
	console.log('The value: "%s", number key becomes typeof %s', resp, typeof resp);
});

//but INCR command on same key will return a number
redis.rawCall(['incr', 'number'], function(err, resp){
	//type of "resp" will be a "number"
	console.log('The value after INCR: "%s", number key becomes typeof %s', resp, typeof resp);
});
//"number" type will be also on INCRBY ZSCORE HLEN and each other redis command which return a number.

//ZRANGE will return an Array, same as redis returns..
redis.rawCall(['zadd', 'sortedset', 1, 'a', 2, 'b', 3, 'c']);
redis.rawCall(['zrange', 'sortedset', 0, -1], function(err, resp){
	//type of will be "number"
	console.log('JSON encoded value of zrange: %s', JSON.stringify(resp));
});

//SCAN, HSCAN, SSCAN and other *SCAN* command will return an Array within Array, like this:
// [ 245, ['key1', 'key2', 'key3'] ]
// first entry (245) - cursor, second one - Array of keys.

//You can pass an object to HMSET redis command
var obj = {
	foo: 'bar',
	hello: 'world',
	integer: 123 //be aware: number type will be returned as a string
};
redis.hmset('HSET:EXAMPLEHASHTABLE', obj);
//rawCall also can handle it
//redis.rawCall(['hmset', 'HSET:EXAMPLEHASHTABLE', obj]);

//HGETALL and HMGET automaticly decode values to object, rawCall do it too
redis.hgetall('HSET:EXAMPLEHASHTABLE', function(err, resp){
	console.log('hgetall command returns err: %s, resp:', err, resp);
});

//Helpers
//=======

//You can use calcSlot function for calculating slot number for key
var slot = redis.calcSlot('привет'); //should be 7365 for this utf-8 key

Notice

  • PUB/SUB still not supported
  • On windows it uses node_redis driver which is much slower

Author

Arseniy Pavlenko (aka h0x91b) https://il.linkedin.com/in/h0x91b

Licence

(The MIT License)

Copyright (c) 2015-2016 Arseniy Pavlenko [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.