UNPKG

simple-redis-pool

Version:

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

1,854 lines (466 loc) 21.6 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>RedisPool - 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="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></ul> </nav> <div id="main"> <h1 class="page-title">RedisPool</h1> <section> <header> <h2> RedisPool </h2> </header> <article> <div class="container-overview"> <h4 class="name" id="RedisPool"><span class="type-signature"></span>new RedisPool<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_pool.js.html">redis_pool.js</a>, <a href="redis_pool.js.html#line45">line 45</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 pool</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="acquire"><span class="type-signature"></span>acquire<span class="signature">(priority, db)</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_pool.js.html">redis_pool.js</a>, <a href="redis_pool.js.html#line154">line 154</a> </li></ul></dd> </dl> <div class="description"> <p>Acquire a Redis connection and use an optional priority.</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>priority</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"><p>priority list number</p></td> </tr> <tr> <td class="name"><code>db</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"><p>Use the db with range {0-16}</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>Promise resolve with the connection or Error</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">promise</span> </dd> </dl> <h4 class="name" id="availableCount"><span class="type-signature"></span>availableCount<span class="signature">()</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_pool.js.html">redis_pool.js</a>, <a href="redis_pool.js.html#line243">line 243</a> </li></ul></dd> </dl> <div class="description"> <p>Returns available connections count of the pool</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>available connections count of the pool</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="destroy"><span class="type-signature"></span>destroy<span class="signature">(client)</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_pool.js.html">redis_pool.js</a>, <a href="redis_pool.js.html#line189">line 189</a> </li></ul></dd> </dl> <div class="description"> <p>Destroy a Redis connection.</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>client</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>Redis connection</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>Promise</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">promise</span> </dd> </dl> <h4 class="name" id="drain"><span class="type-signature"></span>drain<span class="signature">()</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_pool.js.html">redis_pool.js</a>, <a href="redis_pool.js.html#line198">line 198</a> </li></ul></dd> </dl> <div class="description"> <p>Drains the connection pool and call the callback id provided.</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>Promise</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">promise</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_pool.js.html">redis_pool.js</a>, <a href="redis_pool.js.html#line207">line 207</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_pool.js.html">redis_pool.js</a>, <a href="redis_pool.js.html#line225">line 225</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="getPoolSize"><span class="type-signature"></span>getPoolSize<span class="signature">()</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_pool.js.html">redis_pool.js</a>, <a href="redis_pool.js.html#line234">line 234</a> </li></ul></dd> </dl> <div class="description"> <p>Returns size of the pool</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>size of the pool</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">number</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_pool.js.html">redis_pool.js</a>, <a href="redis_pool.js.html#line216">line 216</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="pendingCount"><span class="type-signature"></span>pendingCount<span class="signature">()</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_pool.js.html">redis_pool.js</a>, <a href="redis_pool.js.html#line252">line 252</a> </li></ul></dd> </dl> <div class="description"> <p>Returns pending connections count of the pool</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>pending connections count of the pool</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="release"><span class="type-signature"></span>release<span class="signature">(client)</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_pool.js.html">redis_pool.js</a>, <a href="redis_pool.js.html#line179">line 179</a> </li></ul></dd> </dl> <div class="description"> <p>Release a Redis connection to the pool.</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>client</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="description last"><p>Redis connection</p></td> </tr> </tbody> </table> <h5>Returns:</h5> <div class="param-desc"> <p>Promise</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">promise</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_pool.js.html">redis_pool.js</a>, <a href="redis_pool.js.html#line122">line 122</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="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_pool.js.html">redis_pool.js</a>, <a href="redis_pool.js.html#line261">line 261</a> </li></ul></dd> </dl> <div class="description"> <p>Returns pool status and stats</p> </div> <h5>Returns:</h5> <div class="param-desc"> <p>pool status and stats</p> </div> <dl class="param-type"> <dt> Type </dt> <dd> <span class="param-type">object</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>