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

transparent-redis-layer

v1.0.3

Published

## Installation

Downloads

3

Readme

transparent-redis-layer

Installation

$ npm install transparent-redis-layer

Usage

try to get redis data, if key not exists, fill the data to the corresponding key.

Example


const Redis = require("ioredis");
const CacheLayer = require('./index');
const redis = new Redis({
  port: 6379,         // Redis port
  host: "127.0.0.1",  // Redis host
  family: 4,          // 4 (IPv4) or 6 (IPv6)
  // password: "auth",
  // db: 0
});

const cacheLayer = new CacheLayer();

// if actionForGet not set, then default command is "get". default set command is "set"
// this will "get test:basic", if test:basic not exists, then "set test:basic i am string"
const res = await cacheLayer
  .redisClient(redis)
  .cache('test:basic')
  .from('i am string')
  .exec();

// maintain redis clent
const funcRes = await cacheLayer
  .cache('test:function')
  .actionForGet('lrange', 0, -1)  // lrange test:function 0 -1
  .actionForSet('lpush')          // lpush test:function 0 1 2
  .from(function(){
    return [0, 1, 2];
  })
  .exec();

const promiseRes = await cacheLayer
  .cache('test:promise')
  .actionForGet('hget', 'age')  // hget test:promise age
  // use hmset instead of hset
  .actionForSet('hmset')        // hmset test:promise age 456
  .from(new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({age: 456});
    }, 1000);
  }))
  .exec();

const setParameterRes = await cacheLayer
  .cache('test:parameters')
  .actionForGet('get')        // get test:parameters
  .actionForSet('set', 'NX')  // set test:parameters 123 NX
  .from(async function() {
    return 123;
  })
  .exec();

// change to another redis client
const redis2 = new Redis({
  port: 6379,
  host: "127.0.0.1",
  family: 4,
  db: 1
});

const res = await cacheLayer
  .redisClient(redis2)
  .cache('test:basic')
  .from('i am string')
  .exec();

// customize check function
const cacheLayer = new CacheLayer();
await cacheLayer.redisClient(redis)
  .cache('test:assertFn') // first, put a key
  .from('123')
  .exec();

await cacheLayer
  .cache('test:assertFn')
  .actionForGet('get')        // get test:assertFn
  .assert(async function(res) {
   	return res === '345';   // if test:parameters is not 345, then set test:parameters 345
   })
  .actionForSet('set')  // set test:parameters 123
  .from(async function() {
   	return '345';
   })
  .exec();

See test.js for more examples.

Updates

1.0.3

  • Add assert function,customize check function whether to fill data or not.

License

MIT