@awsmag/power-ec-redis
v1.4.0
Published
A package to connect and work with AWS Elasticache service for Redis
Readme
power-ec-redis
power-ec-redis is a lightweight utility package that simplifies connecting to Amazon ElastiCache for Redis.
It can also be used locally via a Redis Docker container.
Note: Cluster mode is not supported at this time.
🏷️ Badges
✨ Features
- ✅ Simple Redis client initialization
- ✅ Works with AWS ElastiCache & local Redis
- ✅ Optional Koa middleware support
- ✅ Optional env-based config
- ✅ TypeScript ready
📦 Installation
npm install @awsmag/power-ec-redis⚙️ Environment Variables
| Variable | Description |
| ------------------------------- | -------------------- |
| POWER_EC_REDIS_CONNECTION_URI | Redis connection URI |
Environment variables are optional. You may configure them or pass a URI directly.
Example:
POWER_EC_REDIS_CONNECTION_URI=redis://localhost:6379🚀 Usage
Using env variables
import { getRedisClient } from "@awsmag/power-ec-redis";
async function demo() {
const client = await getRedisClient(); // uses POWER_EC_REDIS_CONNECTION_URI
}Passing URI directly
import { getRedisClient } from "@awsmag/power-ec-redis";
async function demo() {
const client = await getRedisClient("redis://localhost:6379");
}🧩 Koa Middleware
Injects a Redis client instance onto ctx.redisClient.
import { getRedisClient, getRedisClientMw } from "@awsmag/power-ec-redis";
import Koa from "koa";
(async () => {
const app = new Koa();
await getRedisClient("redis://localhost:6379");
app.use(getRedisClientMw());
app.use(async (ctx) => {
const redisClient = ctx.redisClient;
await redisClient.set("foo", "bar");
ctx.body = await redisClient.get("foo");
});
app.listen(3000);
console.log("Server running on port 3000");
})();🐳 Local Development
Use Docker to test locally:
docker run -d \
--name redis \
-p 6379:6379 \
redis:latestThen set:
export POWER_EC_REDIS_CONNECTION_URI="redis://localhost:6379"❗ Limitations
- ❌ Redis Cluster mode is not supported
👨🔧 Maintainers
This package is developed and maintained by:
