One part Redis, one part GraphQL, this is RediQLess - a caching tool for APIs.
One part Redis, one part GraphQL, this is RediQLess - a caching tool for APIs. Utilizing GraphQL’s efficient and elegant querying language and Redis’ lightweight caching, we've leveraged these two features to generate a cache of API results. Built for developers, by developers, to facilitate lightweight and performant applications.
Leveraging GraphQL’s declarative query language and strongly typed API with Redis’ inimitable caching mechanism, RediQLess caches unique calls to third-party APIs for ultimate comportability and maximum reusability. RediQLess’ cache functions as a replacement for the API, which can be memory-intensive on the client and server side.
An optimization middleware that leverages the best features of GraphQL and Redis to give developers the most lightweight database possible, with runtime speeds that average to around eighty to ninety percent faster than standard calls to an API. All while avoiding an overabundance of calls to third-party APIs. More specific, more efficient, absolutely RediQLess.
RediQLess as a middleware is powered by two class objects, RediQL and RediCache. RediQL is a dynamic query caching mechanism which leverages the RediCache Class Object to communicate with Redis on your local Redis port to initialize Redis functionaly. The RediCache Class Object uses incoming queries as a map to navigate Redis' key-value store; destructuring the queries into a series of constant time-readable key-value pairs with references to connected nodes. If RediCache finds that incoming query information is stored within Redis, RediCache is able to return that requested data in sub-15ms time. If RediCache does not find the incoming query within the Redis Store, the query is sent back through RediQL to grab the information in the requested API schema via GraphQL. As the data returns to the client, it is simultaneously sent back to RediCache to store that data for future use.
This package is meant to work in conjunction with redis. To install redis:
-
Mac-HomeBrew:
- At the terminal,
brew install redis
- Start redis server with
redis-server
- At the terminal,
-
Linux or Window:
- Download appropriate version of Redis from redis.io/download
- Once installation is completed, start redis server with
redis-server
Once Redis is installed, your server should reflect the below:
- Note: The default port is
6379
const redisClient = redis.createClient({
host: "localhost",
port: 6379,
});
Install RediQLess as an npm module and save it to your package.json as a dependency.
npm install rediqless --save-dev
Create a .env file, to create your PORT which will be leveraged by the RediQLess middleware
Your Server file should reflect the below:
const dotenv = require("dotenv").config();
const PORT = process.env.PORT;
The Express GraphQL Server is leveraged by RediQLess
const graphqlHTTP = require("express-graphql");
const schema = require("./schema/schema");
const { RediQLess } = require("rediqless");
const RediQL = new RediQLess(redisClient);
const RediQLQuery = RediQL.query;
const RediQLClear = RediQL.clearCache;
Below is a typical Express Server set up utilizing RediQLess:
// Require in Express and app
const express = require('express');
const app = express();
// Require/Config dotenv for access to your PORT
const dotenv = require('dotenv').config();
const PORT = process.env.PORT;
// Require GraphQL and Schema
const graphql = require('express-graphql');
const schema = require('./schema/schema');
// Initialize up Redis Client
const redis = require('redis');
const redisClient = redis.createClient({
host: 'localhost',
port: 6379,
});
// Require in RediQLess middleware
const { RediQLess } = require('rediqless');
// Pass redisClient into RediqLess Constructor
const RediQL = new RediQLess(redisClient);
// Implement RediQLess' query capability
const RediQLQuery = RediQL.query;
// Implement RediqLess' cache clearing capability
const RediQLClear = RediQL.clearCache;
// Leverage RediQLess Queries
// ** Assign queries on the front-end to 'req.body.data.query'
app.use('/rediql', RediQLQuery, (req, res) => {
return res.status(202).send(res.locals.query))
});
// Leverage RediQLess Cache Clearing
app.use('/clearcache', RediQLClear, (req, res) => {
return res.status(202).send('Cache Cleared')
});
// RediQLess query will forward request to this Middleware if information is not yet cached
app.use('/graphql', graphqlHTTP.graphqlHTTP({ schema, graphiql: true }));
RediQLess is an open-source community project on Github. While the project is maintained by a small group of dedicated engineers (below), we are grateful to the community for bug fixes, feature development and other contributions.
We welcome contributions to RediQLess, but we also would love to see a thriving third-party ecosystem. If you are interest in creating an open-source project that builds on top of RediQLess, please don't hesitate to reach out, and we'd be happy to provide feedback and support.
This product is licensed under the MIT License - see the LICENSE.md file for details.
This is an open source product.
This product is accelerated by OS Labs.