<h1 id="id-src">src</h1> <p>Simple Redis Cache <a href="https://travis-ci.org/wlaurance/src"><img src="https://travis-ci.org/wlaurance/src.png" alt="Build Status"></a></p> <h3 id="id-usage">Usage</h3> <p>src takes one hash parameter with url and expiry defined. Expiry is the number of seconds a value is non expired in Redis.</p> <pre><code class="hljs language-javascript"><span class="hljs-keyword">var</span> src = <span class="hljs-built_in">require</span>(<span class="hljs-string">'src'</span>); <span class="hljs-keyword">var</span> cache = <span class="hljs-title function_">src</span>( { <span class="hljs-attr">url</span>:<span class="hljs-string">'redis://user:password@example.com:9073/'</span> ,<span class="hljs-attr">expiry</span>:<span class="hljs-number">2</span> } ); </code></pre> <p>Callbacks for set are optional</p> <pre><code class="hljs language-javascript">cache.<span class="hljs-title function_">set</span>(<span class="hljs-string">'key'</span>, <span class="hljs-string">'value'</span>, [cb]); </code></pre> <p>get requires a callback</p> <pre><code class="hljs language-javascript">cache.<span class="hljs-title function_">get</span>(<span class="hljs-string">'key'</span>, <span class="hljs-keyword">function</span>(<span class="hljs-params">err, value</span>){ <span class="hljs-keyword">if</span>(<span class="hljs-keyword">typeof</span> value !== <span class="hljs-string">'undefined'</span>) <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(value); }); </code></pre> <p>If the key has expired, err will not be used to determine this. Err will only be a non null value when an error is thrown from Redis.</p> <p>If you want to delete a key from the cache explicity src provides this functionality through <code>cache.del</code></p> <p>Callbacks are optional for del</p> <pre><code class="hljs language-javascript">cache.<span class="hljs-title function_">del</span>(<span class="hljs-string">'key'</span>, [cb]); </code></pre>