Nutella with Pepperoni and Mushrooms
Miss any of our Open RFC calls?Watch the recordings here! »

apollo-server-cache-redis

1.2.2 • 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

Single instance

const { RedisCache } = require('apollo-server-cache-redis');
 
const server = new ApolloServer({
  typeDefs,
  resolvers,
  cache: new RedisCache({
    host: 'redis-server',
    // Options are passed through to the Redis client
  }),
  dataSources: () => ({
    moviesAPI: new MoviesAPI(),
  }),
});

Sentinels

const { RedisCache } = require('apollo-server-cache-redis');
 
const server = new ApolloServer({
  typeDefs,
  resolvers,
  cache: new RedisCache({
    sentinels: [{
      host: 'sentinel-host-01',
      port: 26379
    }],
    password: 'my_password',
    name: 'service_name',
    // Options are passed through to the Redis client
  }),
  dataSources: () => ({
    moviesAPI: new MoviesAPI(),
  }),
});

Cluster

const { RedisClusterCache } = require('apollo-server-cache-redis');
 
const server = new ApolloServer({
  typeDefs,
  resolvers,
  cache: new RedisClusterCache(
    [{
      host: 'redis-node-01-host',
      // Options are passed through to the Redis cluster client
    }],
    {
      // Cluster options are passed through to the Redis cluster client
    }
  ),
  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

34,878

Version

1.2.2

License

MIT

Unpacked Size

20.6 kB

Total Files

22

Last publish

Collaborators

  • avatar