Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including cache-mongodbredis with all npm packages installed. Try it out:

var cacheMongodbredis = require("cache-mongodbredis")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

cache-mongodbredis v1.0.4

- 1.使用时需要下载好所需依赖Mongoose(4.11)与Redis(2.8)模块 - 2.直接使用引入在项目中后,实例化对象后传入三个参数,mongose对象,redis连接返回的client的对象,缓存在redis中的存活时间 - 3.之后就可以按照mongoose的原生方式来连接数据库、操作数据库 - 4.调用exec方法后就会为当前调用的方法在redis中添加缓存 ```js const mongoose = require("mongoose"); const redis = require("redis"); const client = redis.createClient(6379,"39.106.174.151"); require("cache-mongodbredis")(mongoose,client,100) ``` # 注意事项 当前模块缓存是根据方法名及其参数生成的缓存策略,并且当前相同的方法调用的数据变更后会自动更新缓存

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free