memori
A simple cache/queue library with multiple storage and data type support.
Available adapters
- memory (default)
- redis
Installation
$ npm install memori
Usage
var Memori = ;var cache = ; //-- setcache;cache;cache;//-- expire in 10 secondscache; //-- getcache;cache;cache;cache;
Methods
set(key, value, callback)
set(key, value, ttl, callback)
Set the value of key. If key already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successful operation. The ttl unit is in seconds and value could be of any data type. If ttl is not provided, the default 0 (no expiration) or whatever provided in the constructor options will be used.
//-- set key without expirationcache; //-- set key with 60 second expirationcache;
get(key, callback)
Get the value of key/s. If the key does not exist, a null value is returned.
//-- string keycache; //-- array of keyscache;
del(key, callback)
Removes the specified key/s. The number of keys deleted is returned on successful operation.
//-- string keycache; //-- array of keyscache;
incr(key, callback)
incr(key, value, callback)
Increments the number stored at key by value (defaults to 1 if not provided). If the key does not exist, it is set to 0 before performing the operation.
cache; cache;
decr(key, callback)
decr(key, value, callback)
Decrements the number stored at key by value (defaults to 1 if not provided). If the key does not exist, it is set to 0 before performing the operation.
cache; cache;
keys(pattern, callback)
Returns all keys matching pattern.
Supported glob-style patterns:
- h?llo matches hello, hallo and hxllo
- h*llo matches hllo and heeeello
- h[ae]llo matches hello and hallo
cache;
push(key, value, callback)
Push value at the head of the list stored at key. If key does not exist, it is created as empty list before performing the push operations. When key holds a value that is not a list, an error is returned. It returns the length of the list after the push operations.
cache;
pop(key, callback)
Removes and returns the last element of the list stored at key.
cache;
expire(key, ttl, callback)
Set the timeout of a key. The ttl unit is in seconds.
cache;
Properties
adapter
Returns the name of the active adapter.
console;
identity
Returns the identity of the active adapter.
console;
Options
The constructor accepts the ff. options:
- adapter
- host
- port
- db
- user or username
- password or pass
- ttl
- prefix
- identity
var Memori = ;var cache = adapter: "redis" //-- defaults to "memory" when not provided host: "localhost" port: 6379 password: "abc123" //-- use password to authenticate if not empty db: 1 //-- use db 1 instead of the default 0 ttl: 300 //-- set the default ttl to 300 secs; defaults to 0 when not provided prefix: "my_cache" //-- set key prefix identity: "my_identity" //-- for additional cache key uniqueness;