UNPKG

node-cache-redis-fork

Version:

Simplistic node redis cache ready can scale with generic-pool support

2,016 lines (541 loc) 26.6 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>RedisCache - Documentation</title> <script src="scripts/prettify/prettify.js"></script> <script src="scripts/prettify/lang-css.js"></script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> </head> <body> <input type="checkbox" id="nav-trigger" class="nav-trigger" /> <label for="nav-trigger" class="navicon-button x"> <div class="navicon"></div> </label> <label for="nav-trigger" class="overlay"></label> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="RedisCache.html">RedisCache</a><ul class='methods'><li data-type='method'><a href="RedisCache.html#del">del</a></li><li data-type='method'><a href="RedisCache.html#deleteAll">deleteAll</a></li><li data-type='method'><a href="RedisCache.html#get">get</a></li><li data-type='method'><a href="RedisCache.html#getName">getName</a></li><li data-type='method'><a href="RedisCache.html#getPoolOptions">getPoolOptions</a></li><li data-type='method'><a href="RedisCache.html#getRedisOptions">getRedisOptions</a></li><li data-type='method'><a href="RedisCache.html#getTtl">getTtl</a></li><li data-type='method'><a href="RedisCache.html#keys">keys</a></li><li data-type='method'><a href="RedisCache.html#set">set</a></li><li data-type='method'><a href="RedisCache.html#status">status</a></li><li data-type='method'><a href="RedisCache.html#wrap">wrap</a></li></ul></li><li><a href="RedisPool.html">RedisPool</a><ul class='methods'><li data-type='method'><a href="RedisPool.html#acquire">acquire</a></li><li data-type='method'><a href="RedisPool.html#availableCount">availableCount</a></li><li data-type='method'><a href="RedisPool.html#destroy">destroy</a></li><li data-type='method'><a href="RedisPool.html#drain">drain</a></li><li data-type='method'><a href="RedisPool.html#getName">getName</a></li><li data-type='method'><a href="RedisPool.html#getPoolOptions">getPoolOptions</a></li><li data-type='method'><a href="RedisPool.html#getPoolSize">getPoolSize</a></li><li data-type='method'><a href="RedisPool.html#getRedisOptions">getRedisOptions</a></li><li data-type='method'><a href="RedisPool.html#pendingCount">pendingCount</a></li><li data-type='method'><a href="RedisPool.html#release">release</a></li><li data-type='method'><a href="RedisPool.html#sendCommand">sendCommand</a></li><li data-type='method'><a href="RedisPool.html#status">status</a></li></ul></li><li><a href="RedisStore.html">RedisStore</a><ul class='methods'><li data-type='method'><a href="RedisStore.html#_executeDeleteAll">_executeDeleteAll</a></li><li data-type='method'><a href="RedisStore.html#_loadDeleteAllScript">_loadDeleteAllScript</a></li><li data-type='method'><a href="RedisStore.html#del">del</a></li><li data-type='method'><a href="RedisStore.html#deleteAll">deleteAll</a></li><li data-type='method'><a href="RedisStore.html#expire">expire</a></li><li data-type='method'><a href="RedisStore.html#get">get</a></li><li data-type='method'><a href="RedisStore.html#getName">getName</a></li><li data-type='method'><a href="RedisStore.html#getPoolOptions">getPoolOptions</a></li><li data-type='method'><a href="RedisStore.html#getRedisOptions">getRedisOptions</a></li><li data-type='method'><a href="RedisStore.html#getTtl">getTtl</a></li><li data-type='method'><a href="RedisStore.html#keys">keys</a></li><li data-type='method'><a href="RedisStore.html#ping">ping</a></li><li data-type='method'><a href="RedisStore.html#sendCommand">sendCommand</a></li><li data-type='method'><a href="RedisStore.html#set">set</a></li><li data-type='method'><a href="RedisStore.html#status">status</a></li></ul></li></ul> </nav> <div id="main"> <h1 class="page-title">RedisCache</h1> <section> <header> <h2> RedisCache </h2> </header> <article> <div class="container-overview"> <h4 class="name" id="RedisCache"><span class="type-signature"></span>new RedisCache<span class="signature">(options)</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="redis_cache.js.html">redis_cache.js</a>, <a href="redis_cache.js.html#line15">line 15</a> </li></ul></dd> </dl> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>Accepts properties [&quot;name&quot;, &quot;redisOptions&quot;, &quot;poolOptions&quot;, &quot;logger&quot;]</p> <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>Name your store</p></td> </tr> <tr> <td class="name"><code>redisOptions</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>opts from <a href="https://github.com/NodeRedis/node_redis#options-object-properties">node_redis#options-object-properties</a></p></td> </tr> <tr> <td class="name"><code>poolOptions</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>opts from <a href="https://github.com/coopernurse/node-pool#createpool">node-pool#createpool</a></p></td> </tr> <tr> <td class="name"><code>logger</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>Inject your custom logger</p></td> </tr> <tr> <td class="name"><code>ttlInSeconds</code></td> <td class="type"> <span class="param-type">integer</span> </td> <td class="description last"><p>Number of seconds to store by default</p></td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="del"><span class="type-signature"></span>del<span class="signature">(keys)</span><span class="type-signature"> &rarr; {number}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="redis_cache.js.html">redis_cache.js</a>, <a href="redis_cache.js.html#line87">line 87</a> </li></ul></dd> </dl> <div class="description"> <p>Delete keys</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>keys</code></td> <td class="type"> <span class="param-type">array</span> </td> <td class="description last"><p>keys for the value stored</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>The number of keys that were removed.</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="deleteAll"><span class="type-signature"></span>deleteAll<span class="signature">(pattern)</span><span class="type-signature"> &rarr; {number}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="redis_cache.js.html">redis_cache.js</a>, <a href="redis_cache.js.html#line97">line 97</a> </li></ul></dd> </dl> <div class="description"> <p>Deletes all keys matching pattern</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>pattern</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>glob-style patterns/default '*'</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>The number of keys that were removed.</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="get"><span class="type-signature"></span>get<span class="signature">(key)</span><span class="type-signature"> &rarr; {string}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="redis_cache.js.html">redis_cache.js</a>, <a href="redis_cache.js.html#line63">line 63</a> </li></ul></dd> </dl> <div class="description"> <p>Returns value or null when the key is missing</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>key</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>key for the value stored</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>value or null when the key is missing</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="getName"><span class="type-signature"></span>getName<span class="signature">()</span><span class="type-signature"> &rarr; {string}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="redis_cache.js.html">redis_cache.js</a>, <a href="redis_cache.js.html#line142">line 142</a> </li></ul></dd> </dl> <div class="description"> <p>Returns factory.name for this pool</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>Name of the pool</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="getPoolOptions"><span class="type-signature"></span>getPoolOptions<span class="signature">()</span><span class="type-signature"> &rarr; {object}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="redis_cache.js.html">redis_cache.js</a>, <a href="redis_cache.js.html#line160">line 160</a> </li></ul></dd> </dl> <div class="description"> <p>Returns this.poolOptions for this pool</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>pool options given</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">object</span> </dd> </dl> <h4 class="name" id="getRedisOptions"><span class="type-signature"></span>getRedisOptions<span class="signature">()</span><span class="type-signature"> &rarr; {object}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="redis_cache.js.html">redis_cache.js</a>, <a href="redis_cache.js.html#line151">line 151</a> </li></ul></dd> </dl> <div class="description"> <p>Returns this.redisOptions for this pool</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>redis options given</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">object</span> </dd> </dl> <h4 class="name" id="getTtl"><span class="type-signature"></span>getTtl<span class="signature">(ttlInSeconds)</span><span class="type-signature"> &rarr; {number}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="redis_cache.js.html">redis_cache.js</a>, <a href="redis_cache.js.html#line39">line 39</a> </li></ul></dd> </dl> <div class="description"> <p>Return the ttl or the default set on instantiation</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>ttlInSeconds</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"><p>time to live in seconds</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>ttl</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="keys"><span class="type-signature"></span>keys<span class="signature">(pattern)</span><span class="type-signature"> &rarr; {array}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="redis_cache.js.html">redis_cache.js</a>, <a href="redis_cache.js.html#line73">line 73</a> </li></ul></dd> </dl> <div class="description"> <p>Returns all keys matching pattern</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>pattern</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>glob-style patterns/default '*'</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>all keys matching pattern</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">array</span> </dd> </dl> <h4 class="name" id="set"><span class="type-signature"></span>set<span class="signature">(key, value, ttlInSeconds)</span><span class="type-signature"> &rarr; {string}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="redis_cache.js.html">redis_cache.js</a>, <a href="redis_cache.js.html#line51">line 51</a> </li></ul></dd> </dl> <div class="description"> <p>Returns 'OK' if successful</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>key</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>key for the value stored</p></td> </tr> <tr> <td class="name"><code>value</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>value to stored</p></td> </tr> <tr> <td class="name"><code>ttlInSeconds</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"><p>time to live in seconds</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>'OK' if successful</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="status"><span class="type-signature"></span>status<span class="signature">()</span><span class="type-signature"> &rarr; {object}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="redis_cache.js.html">redis_cache.js</a>, <a href="redis_cache.js.html#line169">line 169</a> </li></ul></dd> </dl> <div class="description"> <p>Returns pool status and stats</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>cache and its store status and stats</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">object</span> </dd> </dl> <h4 class="name" id="wrap"><span class="type-signature"></span>wrap<span class="signature">(key, fn, opts)</span><span class="type-signature"> &rarr; {string}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="redis_cache.js.html">redis_cache.js</a>, <a href="redis_cache.js.html#line114">line 114</a> </li></ul></dd> </dl> <h5 class="subsection-title">Properties:</h5> <table class="props"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>ttlInSeconds</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"><p>time to live in seconds</p></td> </tr> </tbody> </table> <div class="description"> <p>Wraps promise to set its value if not exists.</p> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>key</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>key for the value stored</p></td> </tr> <tr> <td class="name"><code>fn</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"><p>function to call if not cache found</p></td> </tr> <tr> <td class="name"><code>opts</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>options for wrap</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>'OK' if successful</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> </article> </section> </div> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.2</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. </footer> <script>prettyPrint();</script> <script src="scripts/linenumber.js"></script> </body> </html>