@antelopejs/redis
The Redis module of AntelopeJS. It connects one shared ioredis client and serves it to the Redis and Redis Scheduler interfaces.
Interfaces
| Interface | Documentation |
|---|---|
@antelopejs/interface-redis | Redis |
@antelopejs/interface-redis-scheduler | Redis Scheduler |
The scheduler runs inside its interface package on top of the Redis client, so it needs no module besides this one.
Install
ajs project modules add @antelopejs/redis
The command writes the module's default configuration, which connects to redis://localhost:6379.
Configuration
import { defineConfig } from "@antelopejs/interface-core/config";
export default defineConfig({
name: "my-project",
modules: {
redis: {
source: {
type: "package",
package: "@antelopejs/redis",
version: "^1.0.3",
},
config: {
url: "redis://localhost:6379",
useMock: false,
lazyConnect: true,
},
},
},
envOverrides: {
REDIS_URL: "modules.redis.config.url",
},
});
| Key | Description |
|---|---|
url | Redis connection URL. Optional. Without it, the client uses the options below, or localhost:6379. |
useMock | Serves an in-memory ioredis-mock client instead of connecting, and ignores every other key. For tests only. |
| any other key | Passed to the client as ioredis options, such as host, port, password, db, tls or lazyConnect. |
The module creates the client when it starts, and quits it when it stops. With lazyConnect: true, the module waits for the connection before it serves the client.
Quick start
In the module that uses Redis, add the interface:
pnpm add @antelopejs/interface-redis
import { GetClient } from "@antelopejs/interface-redis";
const client = await GetClient();
await client.set("greeting", "hello", "EX", 60);
const greeting = await client.get("greeting");
GetClient() waits until the module has started and set its client. For distributed jobs, add @antelopejs/interface-redis-scheduler and read its documentation.
Documentation
- Redis documents the
@antelopejs/interface-rediscontract that this module implements. - Redis Scheduler documents the
@antelopejs/interface-redis-schedulercontract that this module implements. - Configuration documents module sources,
configblocks and config variables inantelope.config.ts.
Compatibility
| Package | Supported | Tested with |
|---|---|---|
@antelopejs/interface-core | >=0.2.4 <1.0.0 | 0.2.4 |
@antelopejs/interface-redis | >=0.0.9 <1.0.0 | 0.0.9 |
@antelopejs/interface-redis-scheduler | >=0.0.8 <1.0.0 | 0.0.8 |
.nvmrc sets the Node.js release for development, and the dependencies of package.json set the ioredis range.
Contributing
pnpm install
pnpm dev # run the playground/ project against redis://127.0.0.1:6379
pnpm lint
pnpm format:check
pnpm knip
pnpm test # build, then ajs module test with ioredis-mock
The tests need no Redis server. Read the contribution guidelines before you open a pull request.