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

mysql-cache-redis

v0.0.8

Published

A nodejs mysql caching framework based on redis

Downloads

6

Readme

mysql-cache-redis

https://github.com/holleworldabc/mysql-cache-redis

他是什么?

mysql-cache-redis 是一个基于redis的缓存技术来实现mysql的简单有效的缓存技术,
通过redis进行sql查询后mysql-cache-redis会自动将查询的结果进行缓存到redis的0
号数据库,key为sql语句,value为查询结果,并且设置一定的有效时间(每次访问会进行
延迟操作),在下一次进行查询的时候,mysql-cache-redis会自动的从redis中获取数
据,如果数据发送变化redis会清空变化的表的缓存。

使用他你需要准备什么?

  • 必须会使用mysql
  • 必须安装启动redis
  • 必须会nodejs
  • 必须会sql语句

快速上手

安装

npm i mysql-cache-redis -S
# 安装 mysql-cache-redis

配置


const mcr = require('mysql-cache-redis');
const mysql = require('mysql');
const redis = require('redis');
//引入包
const mysqlConfig = {//mysql配置
    host:'localhost',//主机地址
    port:3306,//端口号
    database:'test',//数据库名
    username:'root',//用户名
    password:'',//密码
    connectionLimit:10//池连接限制
    //... 可以使用mysql包的其他配置
};

const redisConfig = {//redis配置
    host:'localhost',//主机地址
    post:6379//端口号
    //... 可以使用redis包的其他配置配置
};

let pool = mysql.createPool(mysqlConfig);
let client = redis.createClient(redisConfig);

const mcroptions = {
    cacheTime: 60 * 60,//缓存时间 -1表示全局不缓存,0表示没有缓存时间
    delayTime: 60 * 30,//下次访问延迟多少秒 -1表示全局不延迟 0表示永不过期
    isRelease: false//是否自动释放默认 不自动释放连接
};
//mysql-cache-reids 的全局配置

mcr.bind(pool,client,mcroptions);
//绑定对象

global.mcr = mcr;
//全局化mcr

使用

查看状态


    mrc.status(true);//查看并打印true表示打印

执行sql语句


    (async ()=>{
        try{
            let connect = mcr.connect();
            let data = await connect.query(`SELECT * FROM TABLE WHERE ID=?;`,[12]);
            connect.release();
        }catch(err){
            
        }
    })();

版本说明

####0.0.5 记录版本信息,优化代码,实现基础操作