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

@redpill-paris/quidol-redis-cache

v3.0.1

Published

Quidol redis cache sdk

Downloads

9

Readme

quidol-redis-cache

Quidol Cache used for our real time show and REST API.

  • Async-mutex included in this package for a reliable cache.
  • Only one connection used per redis Instance, if you instanciante multiple QuidolCache this will not open a new connection but use a connection already open.

Install

  yarn add @redpill-paris/quidol-redis-cache

Configuration

Redis Standalone

const QuidolCache = require('@redpill-paris/quidol-redis-cache');

const redisOptions = {
  host: 'localhost',
  port: '6379',
}

const cache = new QuidolCache({ redisOptions });

Redis Cluster

const QuidolCache = require('@redpill-paris/quidol-redis-cache');

const redisClusterOptions = [
  {
    host: 'localhost',
    port: '6379',
  },
  {
    host: 'localhost',
    port: '6380',
  },
]

const cache = new QuidolCache({ redisClusterOptions, type: 'cluster' });

Redis Cluster

const QuidolCache = require('@redpill-paris/quidol-redis-cache');

const redisSentinelOptions = {
  sentinels: [
    { host: "sentinel-1", port: 26379 },
    { host: "sentinel-2", port: 26379 },
    { host: "sentinel-3", port: 26379 }
  ],
  name: "mymaster"
}

const cache = new QuidolCache({ redisSentinelOptions, type: 'sentinel' });

Parameters available:

  • redisOptions: compatible with all options used in the connect from ioRedis.
  • defaultTTL: default expiration key in seconds(default 60).
  • type: cluster or standalone default(standalone).
  • redisClusterOptions: options passed to Redis.Cluster();

Methods

  • get:
  cache.get(key, storeFunction(optionnal))

return a Promise. If the cache is invalid or null the storeFunction will be executed and the result of this function will be stored in the cache.

const userInfo = await cache.get(
  `userInfo:${userId}`,
  async () => {
    /* Some Async things, fetch user info from DB or other sources.
    ** The method passed in parameter can be sync or async it doesn't matter everything is handled in the package.
    */
    ...
    return userInfo
  }
);

del:

cache.del(key)

Return a Promise.

await cache.del(`userInfo:${userId}`);

delAll

cache.delAll(match, count)

Return a Promise.

await cache.delAll('userInfo:*', 100);

set:

cache.set(key, value)

Return a Promise

await cache.set(`userInfo:${userId}`, {
  admin: true,
  nickname: 'Kubessandra',
});

Exemple:

const QuidolCache = require('@redpill-paris/quidol-redis-cache');

const redisOptions = {
  host: 'localhost',
  port: '6379',
}
const cache = new QuidolCache({ redisOptions });

// Exemple for fetching user info with a cache of 60secs

const userId = '123456';
const userInfo = await cache.get(
  `userInfo:${userId}`,
  async () => {
    /* Some Async things, fetch user info from DB or other sources.
    ** The method passed in parameter can be sync or async it doesn't matter everything is handled in the package.
    */
    ...
    return userInfo
  }
);

// I can now use my userInfo without spamming the database everytime.
console.log(userInfo);

// If the user is Updated, you can del or set the key to invalide the cache and requesting a new fetch on the next req.
await cache.del(`userInfo:${userId}`);

// If there are multiple users, you can delete all this keys
await cache.delAll('userInfo:*', 100);