transparent-redis-layer
Installation
$ npm install transparent-redis-layer
Usage
try to get redis data, if key not exists, fill the data to the corresponding key.
Example
const Redis = ;const CacheLayer = ;const redis = port: 6379 // Redis port host: "127.0.0.1" // Redis host family: 4 // 4 (IPv4) or 6 (IPv6) // password: "auth", // db: 0; const cacheLayer = ; // if actionForGet not set, then default command is "get". default set command is "set"// this will "get test:basic", if test:basic not exists, then "set test:basic i am string"const res = await cacheLayer ; // maintain redis clentconst funcRes = await cacheLayer // lrange test:function 0 -1 // lpush test:function 0 1 2 ; const promiseRes = await cacheLayer // hget test:promise age // use hmset instead of hset // hmset test:promise age 456 ; const setParameterRes = await cacheLayer // get test:parameters // set test:parameters 123 NX ; // change to another redis clientconst redis2 = port: 6379 host: "127.0.0.1" family: 4 db: 1; const res = await cacheLayer ; // customize check functionconst cacheLayer = ;await cacheLayer // first, put a key ; await cacheLayer // get test:assertFn // set test:parameters 123 ;
See test.js
for more examples.
Updates
1.0.3
- Add assert function,customize check function whether to fill data or not.
License
MIT