UNPKG

simple-redis-cache

Version:

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

1,631 lines (433 loc) 21.8 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#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#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#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#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><li data-type='method'><a href="RedisStore.html#ttlInSeconds">ttlInSeconds</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#line14">line 14</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> </tbody> </table> </td> </tr> </tbody> </table> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="deleteAll"><span class="type-signature"></span>deleteAll<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#line78">line 78</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">array</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#line50">line 50</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#line120">line 120</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#line138">line 138</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#line129">line 129</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="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#line62">line 62</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#line38">line 38</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#line147">line 147</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, promise, 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#line96">line 96</a> </li></ul></dd> </dl> <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>promise</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>/ value - 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> </article> </section> </div> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</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>