hybrid-cache - A cache uses memory-cache and Redis
The hybrid-cache caches in-memory and synchronizes on Redis servers. It only supports some basic commands and focuses on fastest response.
Installation
npm install hybrid-cache
Usage Example
'use strict';const HybridCache = ;const hybridCache = ; hybridCache; hybridCache; hybridCache; console;hybridCache;hybridCache; console;hybridCache;hybridCache; ; ; ; ; ; ; ;
This will display:
Error: null Result: OKError: null Result: OK Error: null Result: OKError: null Result: OK Error: null Result: value1Error: null Result: value2 Error: null Result: value1Error: null Result: null Error: null Result: nullError: null Result: null Error: null Result: 10 Error: null Result: nullError: null Result: OKError: null Result: valueInRedisError: null Result: valueInRedis Error: null Result: OKError: null Result: valueInMemError: null Result: valueInMemError: null Result: null Error: null Result: OKError: null Result: valueInMem2Error: null Result: valueInMem2Error: null Result: null Error: null Result: nullError: null Result: nullError: null Result: null
Note that the API is entirely asynchronous. To get data back from the server, you'll need to use a callback.
API
set = function(key, value, callback)
Set key to hold the string value. 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 SET operation.
Return value
Simple string reply: always OK.
setex = function(key, seconds, value, callback)
Set key to hold the string value and set key to timeout after a given number of seconds. An error is returned when seconds is invalid.
Return value
Simple string reply
get = function(key, callback)
Get the value of key. If the key does not exist the special value null is returned.
Return value
Bulk string reply: the value of key, or null when key does not exist or timeout (setWaitingTime function).
incrby = function(key, value, callback)
Increments the number stored at key by increment. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers.
Return value
Integer reply: the value of key after the increment
Redis.*
To only use Redis, Redis.* support full list of commands implemented by Redis. For more details, please refer https://redis.io/commands.
Mem.set = function(key, value, callback)
Set key to hold the string value. 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 SET operation.
Return value
Simple string reply: always OK.
Mem.setex = function(key, seconds, value, callback)
Set key to hold the string value and set key to timeout after a given number of seconds. An error is returned when seconds is invalid.
Return value
Simple string reply
Mem.get = function(key, callback)
Get the value of key. If the key does not exist the special value null is returned.
Return value
Bulk string reply: the value of key, or null when key does not exist.