This package has been deprecated

Author message:

This package is part of the legacy caching implementation used by Apollo Server v2 and v3, and is no longer maintained. We recommend you switch to the newer Keyv-based implementation (which is compatible with all versions of Apollo Server). See https://www.apollographql.com/docs/apollo-server/v3/performance/cache-backends#legacy-caching-implementation for more details.

apollo-server-cache-redis
TypeScript icon, indicating that this package has built-in type declarations

3.3.1 • Public • Published

RedisCache

npm version Build Status

This package exports an implementation of KeyValueCache that allows using Redis as a backing store for resource caching in Data Sources.

It currently supports a single instance of Redis, Cluster and Sentinel.

Usage

This package is built to be compatible with the 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, 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

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

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

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.

Keywords

none

Install

npm i apollo-server-cache-redis

DownloadsWeekly Downloads

45,285

Version

3.3.1

License

MIT

Unpacked Size

20.2 kB

Total Files

23

Last publish

Collaborators

  • apollo-bot