Skip to content

Promise based cache Node module. It provides a single interface for Redis and Memcached basic methods.

Notifications You must be signed in to change notification settings

puricamaykol/node-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node Cache

Build Status Integrated With Travis CI

Promise based cache Node module. It provides a single interface for Redis and Memcached basic methods.


How to install

 npm install mpnode-cache --save

API

  • set([String] key, [String] val) : Promise

  • get([String] key) : Promise

  • setHash([String] key, [JSON] Object) : Promise

  • getHash([String] key) : Promise

  • delete([String] key): Promise

  • getOrFetch([String] key, [Function] callback(done)): Promise

client.getOrFetch('TestKeyGetFetchMC', done=>{
	setTimeout(function(){ done("This is the fetched value"); }, 3000);
         })
         .then(res=>console.log(res))
         .catch(err=>console.log(err));

Example

let cache = require('mpnode-cache');

console.log("memcached");

let client = new cache("127.0.0.1", 6379, "redis");

client.set('TestKey', "TestValue")
		.then(rep => console.log(rep, "respuesta set"))
		.catch(err=>console.log(err, "error set"));

client.get('TestKey')
		.then(rep => console.log(rep, "respuesta get"))
		.catch(err=>console.log(err, "error get"));

let obj = {'att1':"val1"};

client.setHash("testHashKey", obj)
		.then(rep => console.log(rep, "respuesta setHashet"))
		.catch(err=>console.log(err, "error setHash"));

client.getHash("testHashKey")
		.then(rep => console.log(rep, "respuesta getHashet"))
		.catch(err=>console.log(err, "error getHash"));

client.delete("TestKey")
		.then(rep => console.log(rep, "respuesta delete"))
		.catch(err=>console.log(err, "error delete"));

client.get('TestKey')
		.then(rep => console.log(rep, "respuesta get"))
		.catch(err=>console.log(err, "error get"));

client.getOrFetch('TestKeyGetFetchMC', (done)=>{
		setTimeout(function(){ done("This is the fetched value"); }, 3000);
}).then(res=>{
	client.get('TestKeyGetFetchMC')
		.then(rep => console.log(rep, "response TestKeyGetFetchMC"))
		.catch(err => console.log(err, "error TestKeyGetFetchMC"))
}).catch(err=>console.log(err));

The road ahead

  • Replace with Spyies or Stubs both redis clients methods in unit tests

  • Implement auth support

About

Promise based cache Node module. It provides a single interface for Redis and Memcached basic methods.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published