6.4.1 • Published 5 months ago

@tadashi/cache-redis v6.4.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 months ago

cache-redis

NPM version Node.js CI Coverage Status Snyk badge

Using Redis as cache

Install

$ npm i @tadashi/cache-redis

API

new Cache( [opts])

NameTypeDefaultDescription
optsobject{namespace: 'cache', redis: {}}See bellow

opts.addresses:String

Addresses to connect (separated by commas)

opts.namespace:String

The namespace for all cache members

opts.redis:Object

See ioredis options


Cluster

To use Redis.Cluster, set addresses separated by commas:

const cache = new Cache({addresses: '127.0.0.1:6379,127.0.0.1:6380,127.0.0.1:6381'})

Usage

import Cache from '@tadashi/cache-redis'

const _cache = new Cache({
  redis: {
    keyPrefix: 'api'
  },
  namespace: 'example'
})

async function find(key) {
  try {
    const cache = await _cache.get(key)
    if (cache) {
      return cache
    }
    const result = await getDataFromSomeWhere(key)
    await _cache.set(key, result, 'PX', 3600)
    return result
  } catch (err) {
    throw err
  }
}


await find('foo')
// => data from getDataFromSomeWhere

await find('foo')
// => data from cache

Donate ❤️

BTC: bc1q7famhuj5f25n6qvlm3sssnymk2qpxrfwpyq7g4

License

MIT © Thiago Lagden

6.4.1

5 months ago

6.4.0

11 months ago

6.3.1

1 year ago

6.3.0

2 years ago

6.2.0

3 years ago

6.1.0

3 years ago

6.0.0

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.3.0

3 years ago

4.2.0

4 years ago

4.1.5

4 years ago

4.1.4

4 years ago

4.1.3

4 years ago

4.1.2

4 years ago

4.1.1

4 years ago

4.1.0

4 years ago

4.0.0

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.0.0

5 years ago

1.1.0

5 years ago

1.0.0

6 years ago