Socket
Socket
Sign inDemoInstall

redis-cache-promise

Package Overview
Dependencies
5
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    redis-cache-promise

Nodejs Module to handle redis cache with promises


Version published
Weekly downloads
5
decreased by-44.44%
Maintainers
1
Install size
914 kB
Created
Weekly downloads
 

Readme

Source

redis-cache-promise

Very simple module to handle Redis cache key/value with promises

Methods

configure(Object): Set the configuration parameters to connect with Redis, Return the instance of the redis-cache-promise

  • host(string): Host name or ip of the redis server
  • (OPTIONAL) db(int): Database number, default value 0
  • (OPTIONAL) expiry(int): Default value of the cache in seconds, default value : 86400
  • (OPTIONAL) password(string): Password of the Redis server if "requirepass" is set on the server

Promise connect(): Connect with Redis, return a promise.

Example

var Cache = require('redis-cache-promise')

var cache = new Cache()

cache
  .configure({
    host: '192.168.1.36',
    db: 0, //optional default 0
    expiry: 5, //optional default 86400
    password: '123', //optional
  })
  .connect()
  .then(function () {

    cache.set('key',
      {
        value: 'object'
      },
      {
        expiry: 5 // in seconds from now
      })
      .then(function (value) {
        console.log(value)
      }).catch(function (err) {
        throw err
      })

    var interval = setInterval(function () {
      cache.get('key')
        .then(function (value, key) {
          console.log('the value of', key, ' => ', value)
          if (!value) {
            console.log(key, 'expired')
            clearInterval(interval)
          }
        })
        .catch(function (err) {
          throw err
        })

      cache.get('key 2')
        .otherwise(function (deferred, key) {
          var newValue = 'newValue 2'
          console.log(key, 'without value, this function will set the value to ' + newValue)
          return deferred(newValue, {
            expiry: 3
          })
        })
        .then(function (value, key) {
          console.log('the value of', key, ' => ', value)
        })
        .catch(function (err) {
          throw err
        })
    }, 1000)


  })
  .catch(function (err) {
    throw err
  })

#Version 0.1.1

FAQs

Last updated on 16 Jan 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc