Skip to content

Commit

Permalink
update to class
Browse files Browse the repository at this point in the history
  • Loading branch information
pasupulaphani committed May 17, 2020
1 parent 7f727ae commit e98d7fe
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 43 deletions.
44 changes: 22 additions & 22 deletions docs/global.html
Expand Up @@ -84,7 +84,7 @@ <h1 class="navbar-item">node-cache-redis</h1>

<nav>

<h2><a href="index.html">Documentation</a></h2><div class="category"><h3>Global</h3><ul><li><a href="global.html#del">del</a></li><li><a href="global.html#deleteAll">deleteAll</a></li><li><a href="global.html#get">get</a></li><li><a href="global.html#getName">getName</a></li><li><a href="global.html#getPoolOptions">getPoolOptions</a></li><li><a href="global.html#getRedisOptions">getRedisOptions</a></li><li><a href="global.html#getset">getset</a></li><li><a href="global.html#getTtl">getTtl</a></li><li><a href="global.html#init">init</a></li><li><a href="global.html#keys">keys</a></li><li><a href="global.html#set">set</a></li><li><a href="global.html#setTtl">setTtl</a></li><li><a href="global.html#status">status</a></li><li><a href="global.html#wrap">wrap</a></li></ul></div>
<h2><a href="index.html">Documentation</a></h2><div class="category"><h3>Global</h3><ul><li><a href="global.html#del">del</a></li><li><a href="global.html#deleteAll">deleteAll</a></li><li><a href="global.html#get">get</a></li><li><a href="global.html#getName">getName</a></li><li><a href="global.html#getPoolOptions">getPoolOptions</a></li><li><a href="global.html#getRedisOptions">getRedisOptions</a></li><li><a href="global.html#getset">getset</a></li><li><a href="global.html#getTtlInSeconds">getTtlInSeconds</a></li><li><a href="global.html#init">init</a></li><li><a href="global.html#keys">keys</a></li><li><a href="global.html#set">set</a></li><li><a href="global.html#setTtlInSeconds">setTtlInSeconds</a></li><li><a href="global.html#status">status</a></li><li><a href="global.html#wrap">wrap</a></li></ul></div>

</nav>
</div>
Expand Down Expand Up @@ -294,7 +294,7 @@ <h5>Parameters:</h5>
<p class="tag-source">
<a href="redisCache.js.html" class="button">View Source</a>
<span>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line127">line 127</a>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line128">line 128</a>
</span>
</p>

Expand Down Expand Up @@ -467,7 +467,7 @@ <h5>Parameters:</h5>
<p class="tag-source">
<a href="redisCache.js.html" class="button">View Source</a>
<span>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line134">line 134</a>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line135">line 135</a>
</span>
</p>

Expand Down Expand Up @@ -640,7 +640,7 @@ <h5>Parameters:</h5>
<p class="tag-source">
<a href="redisCache.js.html" class="button">View Source</a>
<span>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line113">line 113</a>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line114">line 114</a>
</span>
</p>

Expand Down Expand Up @@ -762,7 +762,7 @@ <h4 class="name" id="getName">
<p class="tag-source">
<a href="redisCache.js.html" class="button">View Source</a>
<span>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line49">line 49</a>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line50">line 50</a>
</span>
</p>

Expand Down Expand Up @@ -884,7 +884,7 @@ <h4 class="name" id="getPoolOptions">
<p class="tag-source">
<a href="redisCache.js.html" class="button">View Source</a>
<span>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line61">line 61</a>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line62">line 62</a>
</span>
</p>

Expand Down Expand Up @@ -1006,7 +1006,7 @@ <h4 class="name" id="getRedisOptions">
<p class="tag-source">
<a href="redisCache.js.html" class="button">View Source</a>
<span>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line55">line 55</a>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line56">line 56</a>
</span>
</p>

Expand Down Expand Up @@ -1229,7 +1229,7 @@ <h5>Parameters:</h5>
<p class="tag-source">
<a href="redisCache.js.html" class="button">View Source</a>
<span>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line103">line 103</a>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line104">line 104</a>
</span>
</p>

Expand Down Expand Up @@ -1286,12 +1286,12 @@ <h5>Parameters:</h5>



<h4 class="name" id="getTtl">
<a class="href-link" href="#getTtl">#</a>
<h4 class="name" id="getTtlInSeconds">
<a class="href-link" href="#getTtlInSeconds">#</a>

<span class="code-name">

getTtl<span class="signature">()</span><span class="type-signature"> &rarr; (nullable) {number}</span>
getTtlInSeconds<span class="signature">()</span><span class="type-signature"> &rarr; (nullable) {number}</span>

</span>
</h4>
Expand Down Expand Up @@ -1351,7 +1351,7 @@ <h4 class="name" id="getTtl">
<p class="tag-source">
<a href="redisCache.js.html" class="button">View Source</a>
<span>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line73">line 73</a>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line74">line 74</a>
</span>
</p>

Expand Down Expand Up @@ -1382,7 +1382,7 @@ <h4 class="name" id="getTtl">

<div class="columns">

<div class='param-desc column is-7'><p>ttl</p></div>
<div class='param-desc column is-7'><p>ttlInSeconds</p></div>


<div class='column is-5 has-text-left'>
Expand Down Expand Up @@ -1638,7 +1638,7 @@ <h5>Parameters:</h5>
<p class="tag-source">
<a href="redisCache.js.html" class="button">View Source</a>
<span>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line25">line 25</a>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line21">line 21</a>
</span>
</p>

Expand Down Expand Up @@ -1786,7 +1786,7 @@ <h5>Parameters:</h5>
<p class="tag-source">
<a href="redisCache.js.html" class="button">View Source</a>
<span>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line120">line 120</a>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line121">line 121</a>
</span>
</p>

Expand Down Expand Up @@ -2009,7 +2009,7 @@ <h5>Parameters:</h5>
<p class="tag-source">
<a href="redisCache.js.html" class="button">View Source</a>
<span>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line91">line 91</a>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line92">line 92</a>
</span>
</p>

Expand Down Expand Up @@ -2066,12 +2066,12 @@ <h5>Parameters:</h5>



<h4 class="name" id="setTtl">
<a class="href-link" href="#setTtl">#</a>
<h4 class="name" id="setTtlInSeconds">
<a class="href-link" href="#setTtlInSeconds">#</a>

<span class="code-name">

setTtl<span class="signature">()</span><span class="type-signature"> &rarr; {number}</span>
setTtlInSeconds<span class="signature">()</span><span class="type-signature"> &rarr; {number}</span>

</span>
</h4>
Expand Down Expand Up @@ -2131,7 +2131,7 @@ <h4 class="name" id="setTtl">
<p class="tag-source">
<a href="redisCache.js.html" class="button">View Source</a>
<span>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line79">line 79</a>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line80">line 80</a>
</span>
</p>

Expand Down Expand Up @@ -2253,7 +2253,7 @@ <h4 class="name" id="status">
<p class="tag-source">
<a href="redisCache.js.html" class="button">View Source</a>
<span>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line67">line 67</a>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line68">line 68</a>
</span>
</p>

Expand Down Expand Up @@ -2528,7 +2528,7 @@ <h5 class="subsection-title">Properties:</h5>
<p class="tag-source">
<a href="redisCache.js.html" class="button">View Source</a>
<span>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line144">line 144</a>
<a href="redisCache.js.html">redisCache.js</a>, <a href="redisCache.js.html#line145">line 145</a>
</span>
</p>

Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Expand Up @@ -84,7 +84,7 @@ <h1 class="navbar-item">node-cache-redis</h1>

<nav>

<h2><a href="index.html">Documentation</a></h2><div class="category"><h3>Global</h3><ul><li><a href="global.html#del">del</a></li><li><a href="global.html#deleteAll">deleteAll</a></li><li><a href="global.html#get">get</a></li><li><a href="global.html#getName">getName</a></li><li><a href="global.html#getPoolOptions">getPoolOptions</a></li><li><a href="global.html#getRedisOptions">getRedisOptions</a></li><li><a href="global.html#getset">getset</a></li><li><a href="global.html#getTtl">getTtl</a></li><li><a href="global.html#init">init</a></li><li><a href="global.html#keys">keys</a></li><li><a href="global.html#set">set</a></li><li><a href="global.html#setTtl">setTtl</a></li><li><a href="global.html#status">status</a></li><li><a href="global.html#wrap">wrap</a></li></ul></div>
<h2><a href="index.html">Documentation</a></h2><div class="category"><h3>Global</h3><ul><li><a href="global.html#del">del</a></li><li><a href="global.html#deleteAll">deleteAll</a></li><li><a href="global.html#get">get</a></li><li><a href="global.html#getName">getName</a></li><li><a href="global.html#getPoolOptions">getPoolOptions</a></li><li><a href="global.html#getRedisOptions">getRedisOptions</a></li><li><a href="global.html#getset">getset</a></li><li><a href="global.html#getTtlInSeconds">getTtlInSeconds</a></li><li><a href="global.html#init">init</a></li><li><a href="global.html#keys">keys</a></li><li><a href="global.html#set">set</a></li><li><a href="global.html#setTtlInSeconds">setTtlInSeconds</a></li><li><a href="global.html#status">status</a></li><li><a href="global.html#wrap">wrap</a></li></ul></div>

</nav>
</div>
Expand Down
41 changes: 21 additions & 20 deletions docs/redisCache.js.html
Expand Up @@ -86,7 +86,7 @@ <h1 class="navbar-item">node-cache-redis</h1>

<nav>

<h2><a href="index.html">Documentation</a></h2><div class="category"><h3>Global</h3><ul><li><a href="global.html#del">del</a></li><li><a href="global.html#deleteAll">deleteAll</a></li><li><a href="global.html#get">get</a></li><li><a href="global.html#getName">getName</a></li><li><a href="global.html#getPoolOptions">getPoolOptions</a></li><li><a href="global.html#getRedisOptions">getRedisOptions</a></li><li><a href="global.html#getset">getset</a></li><li><a href="global.html#getTtl">getTtl</a></li><li><a href="global.html#init">init</a></li><li><a href="global.html#keys">keys</a></li><li><a href="global.html#set">set</a></li><li><a href="global.html#setTtl">setTtl</a></li><li><a href="global.html#status">status</a></li><li><a href="global.html#wrap">wrap</a></li></ul></div>
<h2><a href="index.html">Documentation</a></h2><div class="category"><h3>Global</h3><ul><li><a href="global.html#del">del</a></li><li><a href="global.html#deleteAll">deleteAll</a></li><li><a href="global.html#get">get</a></li><li><a href="global.html#getName">getName</a></li><li><a href="global.html#getPoolOptions">getPoolOptions</a></li><li><a href="global.html#getRedisOptions">getRedisOptions</a></li><li><a href="global.html#getset">getset</a></li><li><a href="global.html#getTtlInSeconds">getTtlInSeconds</a></li><li><a href="global.html#init">init</a></li><li><a href="global.html#keys">keys</a></li><li><a href="global.html#set">set</a></li><li><a href="global.html#setTtlInSeconds">setTtlInSeconds</a></li><li><a href="global.html#status">status</a></li><li><a href="global.html#wrap">wrap</a></li></ul></div>

</nav>
</div>
Expand All @@ -113,11 +113,7 @@ <h1>redisCache.js</h1>
let options = {}
let store = null

const getNumber = num => Number.isNaN(num) &amp;&amp; num >= 0 ? num : null
const getStore = () => {
if (!store) throw NotInitialisedError('RedisCache not initialised')
return store
}
const getNumber = num => !Number.isNaN(num) &amp;&amp; num >= 0 ? num : null

/**
* @param {object} options
Expand Down Expand Up @@ -147,41 +143,46 @@ <h1>redisCache.js</h1>
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
}
Expand All @@ -195,7 +196,7 @@ <h1>redisCache.js</h1>
*/
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)
}

/**
Expand All @@ -207,36 +208,36 @@ <h1>redisCache.js</h1>
*/
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)
}

/**
* Returns value or null when the key is missing
* @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.
Expand All @@ -256,7 +257,7 @@ <h1>redisCache.js</h1>
return fn()
}

const cachedValue = await getStore().get(key)
const cachedValue = await this.getStore().get(key)
if (!cachedValue) {
debug('MISS', {
key
Expand Down

0 comments on commit e98d7fe

Please sign in to comment.