From e98d7feadf1c000588dafcc379c488b1a2db8f32 Mon Sep 17 00:00:00 2001 From: phani Date: Sun, 17 May 2020 18:15:43 +0100 Subject: [PATCH] update to class --- docs/global.html | 44 ++++++++++++++++++++--------------------- docs/index.html | 2 +- docs/redisCache.js.html | 41 +++++++++++++++++++------------------- 3 files changed, 44 insertions(+), 43 deletions(-) diff --git a/docs/global.html b/docs/global.html index 61f31e0..412d23c 100644 --- a/docs/global.html +++ b/docs/global.html @@ -84,7 +84,7 @@

node-cache-redis

@@ -294,7 +294,7 @@
Parameters:

View Source - redisCache.js, line 127 + redisCache.js, line 128

@@ -467,7 +467,7 @@
Parameters:

View Source - redisCache.js, line 134 + redisCache.js, line 135

@@ -640,7 +640,7 @@
Parameters:

View Source - redisCache.js, line 113 + redisCache.js, line 114

@@ -762,7 +762,7 @@

View Source - redisCache.js, line 49 + redisCache.js, line 50

@@ -884,7 +884,7 @@

View Source - redisCache.js, line 61 + redisCache.js, line 62

@@ -1006,7 +1006,7 @@

View Source - redisCache.js, line 55 + redisCache.js, line 56

@@ -1229,7 +1229,7 @@

Parameters:

View Source - redisCache.js, line 103 + redisCache.js, line 104

@@ -1286,12 +1286,12 @@
Parameters:
-

- # +

+ # - getTtl() → (nullable) {number} + getTtlInSeconds() → (nullable) {number}

@@ -1351,7 +1351,7 @@

View Source - redisCache.js, line 73 + redisCache.js, line 74

@@ -1382,7 +1382,7 @@

-

ttl

+

ttlInSeconds

@@ -1638,7 +1638,7 @@
Parameters:

View Source - redisCache.js, line 25 + redisCache.js, line 21

@@ -1786,7 +1786,7 @@
Parameters:

View Source - redisCache.js, line 120 + redisCache.js, line 121

@@ -2009,7 +2009,7 @@
Parameters:

View Source - redisCache.js, line 91 + redisCache.js, line 92

@@ -2066,12 +2066,12 @@
Parameters:
-

- # +

+ # - setTtl() → {number} + setTtlInSeconds() → {number}

@@ -2131,7 +2131,7 @@

View Source - redisCache.js, line 79 + redisCache.js, line 80

@@ -2253,7 +2253,7 @@

View Source - redisCache.js, line 67 + redisCache.js, line 68

@@ -2528,7 +2528,7 @@

Properties:

View Source - redisCache.js, line 144 + redisCache.js, line 145

diff --git a/docs/index.html b/docs/index.html index 28c2d82..9b77c1e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -84,7 +84,7 @@

node-cache-redis

diff --git a/docs/redisCache.js.html b/docs/redisCache.js.html index a75c5d5..2e3d8a6 100644 --- a/docs/redisCache.js.html +++ b/docs/redisCache.js.html @@ -86,7 +86,7 @@

node-cache-redis

@@ -113,11 +113,7 @@

redisCache.js

let options = {} let store = null -const getNumber = num => Number.isNaN(num) && num >= 0 ? num : null -const getStore = () => { - if (!store) throw NotInitialisedError('RedisCache not initialised') - return store -} +const getNumber = num => !Number.isNaN(num) && num >= 0 ? num : null /** * @param {object} options @@ -147,41 +143,46 @@

redisCache.js

store = new RedisStore(options) } +exports.getStore = () => { + if (!store) throw NotInitialisedError('RedisCache not initialised') + return store +} + /** * Returns name of this pool * @returns {string} Name of the pool */ -exports.getName = () => getStore().getName() +exports.getName = () => this.getStore().getName() /** * Returns redisOptions of this pool * @returns {object} redis options given */ -exports.getRedisOptions = () => getStore().getRedisOptions() +exports.getRedisOptions = () => this.getStore().getRedisOptions() /** * Returns poolOptions of this pool * @returns {object} pool options given */ -exports.getPoolOptions = () => getStore().getPoolOptions() +exports.getPoolOptions = () => this.getStore().getPoolOptions() /** * Returns pool status and stats * @returns {object} cache and its store status and stats */ -exports.status = () => getStore().status() +exports.status = () => this.getStore().status() /** * Return the ttlInSeconds - * @returns {number?} ttl + * @returns {number?} ttlInSeconds */ -exports.getTtl = () => options.ttlInSeconds +exports.getTtlInSeconds = () => options.ttlInSeconds /** * Sets the ttlInSeconds * @returns {number} ttl */ -exports.setTtl = ttl => { +exports.setTtlInSeconds = ttl => { options.ttlInSeconds = getNumber(ttl) return options.ttlInSeconds } @@ -195,7 +196,7 @@

redisCache.js

*/ exports.set = async (key, value, ttlInSeconds) => { const ttl = getNumber(ttlInSeconds) || options.ttlInSeconds - return ttl === 0 ? value : getStore().set(key, value, ttl) + return ttl === 0 ? value : this.getStore().set(key, value, ttl) } /** @@ -207,7 +208,7 @@

redisCache.js

*/ exports.getset = async (key, value, ttlInSeconds) => { const ttl = getNumber(ttlInSeconds) || options.ttlInSeconds - return ttl === 0 ? value : getStore().getset(key, value, ttl) + return ttl === 0 ? value : this.getStore().getset(key, value, ttl) } /** @@ -215,28 +216,28 @@

redisCache.js

* @param {string} key - key for the value stored * @returns {any} value or null when the key is missing */ -exports.get = key => getStore().get(key) +exports.get = key => this.getStore().get(key) /** * Returns all keys matching pattern * @param {string} pattern - glob-style patterns/default '*' * @returns {array} all keys matching pattern */ -exports.keys = (pattern = '*') => getStore().keys(pattern) +exports.keys = (pattern = '*') => this.getStore().keys(pattern) /** * Delete keys * @param {array} keys - keys for the value stored * @returns {number} The number of keys that were removed. */ -exports.del = keys => getStore().del(keys) +exports.del = (keys = []) => this.getStore().del(keys) /** * Deletes all keys matching pattern * @param {string} pattern - glob-style patterns/default '*' * @returns {number} The number of keys that were removed. */ -exports.deleteAll = (pattern = '*') => getStore().deleteAll(pattern) +exports.deleteAll = (pattern = '*') => this.getStore().deleteAll(pattern) /** * Wraps promise to set its value if not exists. @@ -256,7 +257,7 @@

redisCache.js

return fn() } - const cachedValue = await getStore().get(key) + const cachedValue = await this.getStore().get(key) if (!cachedValue) { debug('MISS', { key