This example illustrates using Redis as a data store. Commonly used to share state in a distrubuted environment.
Use RateLimiterRedis
along with a redis
or ioredis
client.
A Redis server is required and the GraphQL server needs to know how to connect to it.
Use Redis Labs' free subscription for a small cloud hosted Redis database. See Creating a Subscription.
Download, install, and configure Redis.
This example requires a url
and password
to a Redis database.
yarn install
cp .env.sample .env
In .env
file, set REDIS_URL
and REDIS_PASSWORD
. These values are used on server startup.
Example .env
content:
REDIS_URL=redis://redis-12345.c14.us-east-1-2.ec2.cloud.redislabs.com:12345
REDIS_PASSWORD=MySecretString
node index.js
Navigate to http://localhost:4000/graphql
in a browser.
Server is configured to allow each root field to be queried once every 15 seconds. Sample query:
{
quote
books {
title
author
}
}