# @zcong/redis-cache

> my cool project

Latest version **0.6.0** (published 2021-01-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @zcong/redis-cache
pnpm add @zcong/redis-cache
yarn add @zcong/redis-cache
bun add @zcong/redis-cache
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2021-01-27 |
| First published | 2020-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 40.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | zcong1993 |
| Maintainers | zcong |

## Links

- npm: https://www.npmjs.com/package/@zcong/redis-cache
- npm.io page: https://npm.io/package/@zcong/redis-cache

## Dependencies (2)

- [debug](https://npm.io/package/debug.md) ^4.1.1
- [@zcong/singleflight](https://npm.io/package/@zcong/singleflight.md) ^0.1.3

## Recent versions

- 0.6.0 (latest) — 2021-01-27
- 0.5.1 — 2020-12-10
- 0.4.0 — 2020-09-15
- 0.3.0 — 2020-07-11
- 0.2.0 — 2020-03-13
- 0.1.2 — 2020-03-11
- 0.1.1 — 2020-03-11
- 0.1.0 — 2020-03-11

## README

# redis-cache

[![NPM version](https://img.shields.io/npm/v/@zcong/redis-cache.svg?style=flat)](https://npmjs.com/package/@zcong/redis-cache) [![NPM downloads](https://img.shields.io/npm/dm/@zcong/redis-cache.svg?style=flat)](https://npmjs.com/package/@zcong/redis-cache) [![CircleCI](https://circleci.com/gh/zcong1993/redis-cache/tree/master.svg?style=shield)](https://circleci.com/gh/zcong1993/redis-cache/tree/master) [![codecov](https://codecov.io/gh/zcong1993/redis-cache/branch/master/graph/badge.svg)](https://codecov.io/gh/zcong1993/redis-cache)

## Install

```bash
$ yarn add @zcong/redis-cache
# or
$ npm i @zcong/redis-cache --save
```

## Usage

see [./src/example.ts](./src/example.ts)

```ts
const rc = new RedisCache({ client: new Redis(), nonExistsExpire: 100 })

// cache map result: keys -> Map<key, value>
const mapFn = async (keys: string[]): Promise<Map<string, Res>> => {
  const mp = new Map<string, Res>()
  keys.forEach(k => {
    mp.set(k, genRes(k))
  })
  return mp
}
// cache result 1000s
await rc.batchGet('test-map', mapFn, ['test1', 'test2'], 1000)

// cache array result: keys -> [{ key, value }]
const arrFn = async (keys: string[]): Promise<Res[]> => {
  await sleep(1000)
  return keys.map(genRes)
}

await rc.batchGetArray('test', arrFn, ['test1', 'test2'], 'k', 1000)

// get one, key => result
const singleFn = async (key: string): Promise<Res> => {
  await sleep(1000)
  return genRes(key)
}

await rc.getOne('single', singleFn, 'test', 1000)

// cache void function result: () => result
const fn = async (): Promise<Res> => {
  await sleep(1000)
  return genRes('test')
}

await rc.cacheFn('fn-test', fn, 1000)
```

## License

MIT &copy; zcong1993

---
_Source: https://npm.io/package/@zcong/redis-cache · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
