# apollo-server-cache-redis

> [![npm version](https://badge.fury.io/js/apollo-server-cache-redis.svg)](https://badge.fury.io/js/apollo-server-cache-redis) [![Build Status](https://circleci.com/gh/apollographql/apollo-server/tree/main.svg?style=svg)](https://circleci.com/gh/apollograph

Latest version **3.3.1** (published 2022-01-18) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install apollo-server-cache-redis
pnpm add apollo-server-cache-redis
yarn add apollo-server-cache-redis
bun add apollo-server-cache-redis
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.3.1 |
| Published | 2022-01-18 |
| First published | 2018-07-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12.0 |
| Dependencies | 4 |
| Unpacked size | 19.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13958 |
| Author | Apollo |
| Maintainers | apollo-bot |

## Links

- npm: https://www.npmjs.com/package/apollo-server-cache-redis
- Repository: https://github.com/apollographql/apollo-server
- Homepage: https://github.com/apollographql/apollo-server#readme
- Issues: https://github.com/apollographql/apollo-server/issues
- npm.io page: https://npm.io/package/apollo-server-cache-redis

## Dependencies (4)

- [ioredis](https://npm.io/package/ioredis.md) ^4.17.3
- [dataloader](https://npm.io/package/dataloader.md) ^2.0.0
- [apollo-server-env](https://npm.io/package/apollo-server-env.md) ^4.2.1
- [apollo-server-caching](https://npm.io/package/apollo-server-caching.md) ^3.3.0

## Recent versions

- 3.3.1 (latest) — 2022-01-18
- 1.6.0 (v2) — 2022-08-18
- 3.2.0-alpha.0 (alpha) — 2021-10-09
- 3.1.0 (next) — 2021-08-23
- 3.0.0-rc.1 (rc) — 2021-07-02
- 3.0.0-preview.3 (preview) — 2021-06-26
- 1.4.1-unified2.0 (unified) — 2021-04-22
- 3.0.0-alpha.3 (next-v3) — 2020-08-12
- 3.3.0 — 2021-11-05
- 3.2.0 — 2021-10-11
- 3.1.0-alpha.0 — 2021-08-20
- 3.0.3 — 2021-07-26
- 3.0.2 — 2021-07-20
- 3.0.1 — 2021-07-16
- 3.0.0 — 2021-07-07
- … 55 more at https://npm.io/package/apollo-server-cache-redis/versions

## README

## RedisCache

[![npm version](https://badge.fury.io/js/apollo-server-cache-redis.svg)](https://badge.fury.io/js/apollo-server-cache-redis)
[![Build Status](https://circleci.com/gh/apollographql/apollo-server/tree/main.svg?style=svg)](https://circleci.com/gh/apollographql/apollo-server)

This package exports an implementation of `KeyValueCache` that allows using Redis as a backing store for resource caching in [Data Sources](https://www.apollographql.com/docs/apollo-server/data/data-sources).

It currently supports a single instance of Redis, [Cluster](http://redis.io/topics/cluster-tutorial) and [Sentinel](http://redis.io/topics/sentinel).

## Usage

This package is built to be compatible with the [ioredis](https://www.npmjs.com/package/ioredis) Redis client. The recommended usage is to use the `BaseRedisCache` class which takes either a `client` option (a client that talks to a single server) or a `noMgetClient` option (a client that talks to Redis Cluster). (The difference is that ioredis [only supports the `mget` multi-get command in non-cluster mode](https://github.com/luin/ioredis/issues/811), so using `noMgetClient` tells `BaseRedisCache` to use parallel `get` commands instead.)

You may also use the older `RedisCache` and `RedisClusterCache` classes, which allow you to pass the ioredis constructor arguments directly to the cache class's constructor.
### Single instance

```js
const { BaseRedisCache } = require('apollo-server-cache-redis');
const Redis = require('ioredis');

const server = new ApolloServer({
  typeDefs,
  resolvers,
  cache: new BaseRedisCache({
    client: new Redis({
      host: 'redis-server',
    }),
  }),
  dataSources: () => ({
    moviesAPI: new MoviesAPI(),
  }),
});
```

### Sentinels

```js
const { BaseRedisCache } = require('apollo-server-cache-redis');
const Redis = require('ioredis');

const server = new ApolloServer({
  typeDefs,
  resolvers,
  cache: new BaseRedisCache({
    client: new Redis({
      sentinels: [{
        host: 'sentinel-host-01',
        port: 26379
      }],
      password: 'my_password',
      name: 'service_name',
    }),
  }),
  dataSources: () => ({
    moviesAPI: new MoviesAPI(),
  }),
});
```

### Cluster

```js
const { BaseRedisCache } = require('apollo-server-cache-redis');
const Redis = require('ioredis');

const server = new ApolloServer({
  typeDefs,
  resolvers,
  cache: new BaseRedisCache({
    noMgetClient: new Redis.Cluster(
      [{
        host: 'redis-node-01-host',
        // Options are passed through to the Redis cluster client
      }],
      {
        // Redis cluster client options
      }
    ),
  }),
  dataSources: () => ({
    moviesAPI: new MoviesAPI(),
  }),
});
```

For documentation of the options you can pass to the underlying redis client, look [here](https://github.com/luin/ioredis).

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