@awsmag/power-ec-redis
v1.2.0
Published
A package to connect and work with AWS Elasticache service for Redis
Downloads
10
Readme
power-ec-redis
A package to help connect and work with Amazon Elasticache for Redis. You can run this package locally by connecting to a redis docker container.
This package does not support cluster.
Badges
Environment Variables
The package supports two env variables
POWER_EC_REDIS_CONNECTION_URI
: Connection string to connect
env vars are optional. You can either configure these or can pass them to the function.
Installation
install the package fron npm
npm install @awsmag/power-ec-redis
Usage/Examples
import { getRedisClient } from "@awsmag/power-ec-redis";
async function useWithEnvVarSet() {
return await getRedisClient(); // if env variables are set
}
async function useWithoutEnvVarSet() {
const url = "redis://localhost:6379";
return await getRedisClient(url); // if env variables are not set
}
The package also supports a Koa middleware to attach the client to ctx.
import { getRedisClient, getRedisClientMw } from "@awsmag/power-ec-redis";
import Koa from "koa";
const server = new Koa();
const url = "redis://localhost:6379";
(async () => {
await getRedisClient(url);
server.use(getRedisClientMw());
// rest of your code goes here
})();
// it will be available as `redisClient` in ctx. In your handler use it like below.
// perform functions using redisClient
const redisClient = ctx.redisClient;
The package is developed and maintained by S25Digital. You can also check our blog AWSMAG