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

runing-redis

v1.1.2

Published

- 运行中的 redis,程序终止数据也就没了

Downloads

7

Readme

runing-redis

  • 运行中的 redis,程序终止数据也就没了

use

const Redis = require('runing-redis');

const r = new Redis(50000);  // 限制大小(字节)

(async () => {
  const d = await r.deposit('a', 11111, 3000);
  console.log('d :>> ', d);  //--> { cache: false, data: 11111 }

  setTimeout(async() => {
    const d = await r.deposit('a', 22222, 1000);
    console.log('d :>> ', d);  //--> { cache: true, data: 11111 }
  }, 2000)
})()
  • 支持异步存储
r.deposit('a', async() => await promise, 3000);

koa 中使用

  • 封装下 runing-redis
const Redis = require('runing-redis');
const redis = new Redis(50000);

export default {
  /**
   * 储存数据,如果已经存在并且没有过期你会直接获取到该数据
   * @param {string} ctx
   * @param {*} value 是一个函数时(必须返回数据):可以进行数据请求,有缓存时并不会执行;其他类型:直接将数据存放进去
   * @param {date} overTime 过期时间,为 -1 时数据不过期。设置更小的数无意义
   * @param {boolean} cover 强制覆盖数据
   * @param {boolean} cache 想知道有获取的数据有没有缓存
   * @returns 返回设置的 value
   */
  async deposit(ctx, value, overTime = -1, cover = false, cache = false) {
    let res = null;
    if (['string', 'symbol'].includes(typeof ctx)) {
      res = await redis.deposit(ctx, value, overTime, cover)
    } else {
      res = await redis.deposit(ctx.request.url, value, overTime, cover)
      ctx.state.redis_cache = res.cache;
    }
    if (cache) return res;
    else return res.data;
  },

  // 清除数据(过期的,早以前的)
  clearCache: redis.clearCache,

  // 删除过期的数据
  deleteFristValue: redis.deleteFristValue,

  // 删除最早缓存的数据
  deleteOverValue: redis.deleteOverValue,
}
user.get('/list', async(ctx, next) => {

  const data = await redis.deposit(ctx, async () => {
    return await sql_getUserList();  // runing-redis 中有缓存数据就不会运行
  }, 100000)

  ctx.body = data;
  next();
})