Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including apollo-server-cache-redis with all npm packages installed. Try it out:

var apolloServerCacheRedis = require("apollo-server-cache-redis")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

apollo-server-cache-redis v1.2.2

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.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free