@elysiumjs/redis

中文文档
0.2.1发布于 2026/11/13Apache-2.0TypeScriptES Module近 30 天下载 3423

Redis backend for the Elysium.js framework: connections, caches, rate limits, locks, Heracles queues and workers, flow and session stores.

原始使用文档
文档目录9 节
  1. Installation
  2. Connections
  3. Lock
  4. Cache store
  5. Rate limits
  6. Heracles
  7. Flows
  8. Sessions
  9. License

@elysiumjs/redis

Redis for Elysium.js: connections, a lock driver, a cache store, rate limits, a Heracles transport with its worker, and flow and session stores.

Installation

bun add @elysiumjs/olympus @elysiumjs/redis

Connections

RedisModule registers each connection as a global service named redis.connection.{name}. Clients are created on first use.

import { runtime as bunRuntime } from '@elysiumjs/bun';
import { Application } from '@elysiumjs/olympus';
import { Redis, RedisModule } from '@elysiumjs/redis';

@Application.register({
    runtime: bunRuntime,
    modules: [
        RedisModule.with({
            default: 'cache',
            connections: { cache: { url: process.env.REDIS_URL! } }
        })
    ]
})
class App extends Application {}

const client = Redis.getConnection('cache');

The default client is Bun.RedisClient. Pass client in the module config to use another one: ioredis(...) wraps an ioredis client, and upstash({ token }) talks to Upstash over HTTP, which also works on Cloudflare Workers.

Lock

Importing the package registers the redis driver of the Lock port. A lock is a key set with SET NX PX; Lua scripts release and extend it only for its holder.

import { Lock } from '@elysiumjs/olympus';
import { HeraclesModule } from '@elysiumjs/olympus/heracles';

import '@elysiumjs/redis';

HeraclesModule.with({ lock: Lock.for('redis', { connection: 'cache', prefix: 'lock:' }) });

Cache store

KeyvRedis is a Keyv store over a connection, for the caches of @elysiumjs/olympus/mnemosyne:

import { MnemosyneModule } from '@elysiumjs/olympus/mnemosyne';
import { KeyvRedis } from '@elysiumjs/redis';

MnemosyneModule.with({
    cache: { stores: { redis: () => new KeyvRedis({ connection: 'cache' }) } }
});
// Cache.store('redis')

Rate limits

RedisRateLimitStore keeps the counters of RateLimit in Redis, so every instance of the app shares them.

Heracles

RedisTransport carries the jobs of a queue on Redis streams. HeraclesRedisModule adds two commands: heracles:work runs a worker that consumes the queues, and heracles:clean removes finished jobs from the streams.

import { HeraclesModule } from '@elysiumjs/olympus/heracles';
import { HeraclesRedisModule, RedisTransport } from '@elysiumjs/redis';

@Application.register({
    modules: [
        RedisModule.with({ connections: { default: { url: process.env.REDIS_URL! } } }),
        HeraclesModule.with({ queues: { emails: { transport: RedisTransport } } }),
        HeraclesRedisModule
    ]
})
class App extends Application {}
styx heracles:work --id worker-1 --queues emails --redis default

Flows

RedisFlowStore keeps the flows of @elysiumjs/olympus/ariadne:

import { AriadneModule } from '@elysiumjs/olympus/ariadne';
import { Redis, RedisFlowStore } from '@elysiumjs/redis';

AriadneModule.with({
    store: new RedisFlowStore({ connection: () => Redis.getConnection(), prefix: 'flow:' })
});

Each flow is a hash under {prefix}{flow:flowKey}, with a lease key that expires on its own and, once the flow is finished, a marker that keeps its owner and end time for its TTL. The keys of a flow share a hash tag, so they live on the same cluster slot.

Sessions

RedisSessionStore keeps the sessions of @elysiumjs/olympus/themis, on any connection, Upstash included:

import { ThemisModule } from '@elysiumjs/olympus/themis';
import { Redis, RedisSessionStore } from '@elysiumjs/redis';

ThemisModule.with({
    secret: env.APP_SECRET,
    session: {
        store: new RedisSessionStore({ connection: () => Redis.getConnection(), prefix: 'session:' })
    }
});

Each session is a JSON value under {prefix}{id} (session: by default), which expires with the session.

License

Apache-2.0

版本与发布记录

@elysiumjs/redis 共发布 17 个版本,首次发布于 2026/11/07;过去 12 个月发布了 17 个版本。

版本发布日期距今
0.2.1latest2026/11/13今天
0.2.02026/11/13今天
0.1.132026/11/121 天前
0.1.122026/11/112 天前
0.1.112026/11/112 天前
0.1.102026/11/112 天前

关于 @elysiumjs/redis 的常见问题

@elysiumjs/redis 是什么?

Redis backend for the Elysium.js framework: connections, caches, rate limits, locks, Heracles queues and workers, flow and session stores.

如何安装 @elysiumjs/redis?

在项目目录运行 npm install @elysiumjs/redis,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@elysiumjs/olympus(^0.26.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@elysiumjs/redis 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@elysiumjs/redis 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@elysiumjs/redis 可以商用吗?

@elysiumjs/redis 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@elysiumjs/redis 的下载量有多少?

根据 npm 官方下载统计,@elysiumjs/redis 在 2026/10/14 – 2026/11/12 这 30 天内被下载 3,423 次,日均约 114 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@elysiumjs/redis 还在维护吗?

最新版本 0.2.1 发布于 2026/11/13(今天);至今共发布 17 个版本,其中过去 12 个月发布了 17 个;首次发布于 2026/11/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。