This project borrowed from mongoose-redis-cache.
The difference is that this project using javascript alternative coffeescript, support custom redis client, and change some internal logics and using methods.
Installation
`npm install mongoose-with-redis
Example Usage
var mongoose = require('mongoose');
var redis = require('ioredis');
var MongooseRedis = require('mongoose-with-redis');
var userSchama = new mongoose.Schema({
name: String,
age: Number,
});
User = mongoose.model('User', userSchama);
var redisClient = redis.createClient();
mongoose.connect('mongodb://localhost/mongoose-redis-test');
var cacheOptions = {
cache: true,
expires: 60,
prefix: 'RedisCache'
};
MongooseRedis(mongoose, redisClient, cacheOptions);
var user = yield User.findOne({name: 'xxx'}).lean().exec();
var user = yield User.findOne({name: 'xxx'}).exec();
var user = yield User.findOne({name: 'xxx'})
.setOptions({cacheOptions: {cache: false}})
.lean().exec();