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

redis-speed

v1.2.0

Published

An utility for redis aim to improve the performance of redis.

Downloads

7

Readme

redis-speed

An utility for redis aim to improve the performance of redis, it includes FlashCacheRedis now.

build status Test coverage David deps node version

NPM

FlashCacheRedis

Save value in memory to reduce the frequency of reading redis.

Usage

const {FlashCacheRedis} = require('redis-speed');
const Redis = require('ioredis');
const redisClient = new Redis();//connect to the redis server of localhost:6379
const {cacheQueryAdapter} = new FlashCacheRedis({
    redisClient,//the redis client object
    interval:1000
});
const {expect} = require('chai');
const KEY = 'flash_cache_redis:basic';
const VALUE = {name:'sunny',id:1};

redisClient.set(KEY,JSON.stringify(VALUE),function(err) {//save session
    if (err) {
        return console.error(err);
    }
    //It will cache the value in FlashCacheRedis instance, when you call the function of `cacheQueryAdapter.get` next, it will read the value directly from memory.
    cacheQueryAdapter.get(KEY,function(err,obj) {
        if (err) {
            return console.error(err);
        }
        try {
            obj = JSON.parse(obj);
        } catch (e) {
            return console.error(e);
        }
        expect(obj).to.have.property('name').and.equal(VALUE.name);
    });
});

RedisHelper

An utility class to do parallel job with redis. If your redis is run in cluster mode, it will not return the data properly with some functions, such as pipeline or mutil. RedisHelper is designed to resoved such issue.

Usage

const {RedisHelper} = require('redis-speed');
const key1 = 'key1';
const value1 = Math.random() + '';
const key2 = 'key2';
const value2 = Math.random() + '';
const tasks = [
    ['set',key1,value1],
    ['set',key2,value2]
];
redisHelper.doParallelJobs(tasks,function(none,[[err1],[err2]]) {

});

redisBatchIncr

An utility class to send redis command in batch.

Usage

const {
    redisBatchIncr: {
        EVENT_ONE_LOOP_FINISHED,
        EVENT_SEND_ERROR,
        BatchHincr,
        BatchZincrby
    }
} = require('redis-speed');
const redisClient = new Redis();//connect to the redis server of localhost:6379

const LOOP_COUNT = 100;
const INTERVAL = 200;
const key = ('test:' + Math.random()).replace('.','');
const cmd = new BatchHincr({redisClient,loopInterval:INTERVAL,key});

cmd.on(EVENT_ONE_LOOP_FINISHED,function() {
    redisClient.hget(key,'name',function(err,reply) {
        if (err) {
            return console.error(err);
        }
        expect(Number(reply)).to.be.equal(LOOP_COUNT);
    });
});
cmd.on(EVENT_SEND_ERROR,function(err) {
    console.error(err);
});

for(var i=0;i<LOOP_COUNT;i++) {
    cmd.addData(1,'name');
}

redisMultiBatchIncr

An utility class to send redis command in batch with multiple keys.

Usage

const {
    redisMultiBatchIncr: {
        EVENT_ONE_LOOP_FINISHED,
        EVENT_SEND_ERROR,
        BatchMultiHincr,
        BatchMultiZincrby
    }
} = require('redis-speed');
const redisClient = new Redis();//connect to the redis server of localhost:6379

const LOOP_COUNT = 100;
const INTERVAL = 200;

const cmd = new BatchMultiHincr({redisClient,loopInterval:INTERVAL});
const key = ('test:' + Math.random()).replace('.','');
cmd.on(EVENT_ONE_LOOP_FINISHED,function() {
    redisClient.hget(key,'name',function(err,reply) {
        if (err) {
            return done(err);
        }
        expect(Number(reply)).to.be.equal(LOOP_COUNT);
        done();
    });
});
cmd.on(EVENT_SEND_ERROR,function(err) {
    done(err);
});

for(var i=0;i<LOOP_COUNT;i++) {
    cmd.addData(key,1,'name');
}

API

api

License

MIT