UNPKG

simple-redis-cache

Version:

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

2,251 lines (597 loc) 29 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>RedisStore - 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">RedisStore</h1> <section> <header> <h2> RedisStore </h2> </header> <article> <div class="container-overview"> <h4 class="name" id="RedisStore"><span class="type-signature"></span>new RedisStore<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_store.js.html">redis_store.js</a>, <a href="redis_store.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="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_store.js.html">redis_store.js</a>, <a href="redis_store.js.html#line147">line 147</a> </li></ul></dd> </dl> <div class="description"> <p>Returns the number of keys that were removed - See <a href="https://redis.io/commands/del">redis del</a></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>list of keys to delete</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; {array}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="redis_store.js.html">redis_store.js</a>, <a href="redis_store.js.html#line192">line 192</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="expire"><span class="type-signature"></span>expire<span class="signature">(key, 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_store.js.html">redis_store.js</a>, <a href="redis_store.js.html#line158">line 158</a> </li></ul></dd> </dl> <div class="description"> <p>Returns 1 if the timeout was set/ 0 if key does not exist or the timeout could not be set - See <a href="https://redis.io/commands/expire">redis expire</a></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 to set expire</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>1 if the timeout was set successfully; if not 0</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_store.js.html">redis_store.js</a>, <a href="redis_store.js.html#line120">line 120</a> </li></ul></dd> </dl> <div class="description"> <p>Returns value or null when the key is missing - See <a href="https://redis.io/commands/get">redis get</a></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_store.js.html">redis_store.js</a>, <a href="redis_store.js.html#line71">line 71</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_store.js.html">redis_store.js</a>, <a href="redis_store.js.html#line89">line 89</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_store.js.html">redis_store.js</a>, <a href="redis_store.js.html#line80">line 80</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_store.js.html">redis_store.js</a>, <a href="redis_store.js.html#line178">line 178</a> </li></ul></dd> </dl> <div class="description"> <p>Returns all keys matching pattern - See <a href="https://redis.io/commands/keys">redis keys</a></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="ping"><span class="type-signature"></span>ping<span class="signature">(str)</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_store.js.html">redis_store.js</a>, <a href="redis_store.js.html#line110">line 110</a> </li></ul></dd> </dl> <div class="description"> <p>Returns supplied string if not return 'PONG'</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>str</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>Optional string</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>supplied string if not return 'PONG'</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="sendCommand"><span class="type-signature"></span>sendCommand<span class="signature">(commandName, commandArgs)</span><span class="type-signature"> &rarr; {promise}</span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="redis_store.js.html">redis_store.js</a>, <a href="redis_store.js.html#line100">line 100</a> </li></ul></dd> </dl> <div class="description"> <p>Send redis instructions</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>commandName</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last"><p>Name of the command</p></td> </tr> <tr> <td class="name"><code>commandArgs</code></td> <td class="type"> <span class="param-type">array</span> </td> <td class="description last"><p>Args sent to the command</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>Promise resolve with the result or Error</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">promise</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_store.js.html">redis_store.js</a>, <a href="redis_store.js.html#line132">line 132</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_store.js.html">redis_store.js</a>, <a href="redis_store.js.html#line216">line 216</a> </li></ul></dd> </dl> <div class="description"> <p>Returns pool status and stats</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>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="ttlInSeconds"><span class="type-signature"></span>ttlInSeconds<span class="signature">(key)</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_store.js.html">redis_store.js</a>, <a href="redis_store.js.html#line168">line 168</a> </li></ul></dd> </dl> <div class="description"> <p>Returns TTL in seconds, or a negative value in order to signal an error - See <a href="https://redis.io/commands/ttl">redis ttl</a></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>list of keys to delete</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>TTL in seconds, or a negative value in order to signal an error</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">number</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>