@elysiumjs/ redis (英语)
重写为 极乐世界:连接,锁驱动,缓存商店,速率限制,Heracles与工人的运输,以及流量和会话商店.
安装
bun add @elysiumjs/olympus @elysiumjs/redis
连接
RedisModule 将每个连接登记为全球服务 redis.connection.{name}。客户端是先使用的.
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');
默认客户端是 Bun.RedisClient。通过 client 在模块配置中使用另一个: ioredis(...) 包裹一个 ioredis 客户端,并且 upstash({ token }) 与Upstash就HTTP进行会谈,HTTP也致力于Cloudflare工人.
锁定
导入软件包注册 redis 驱动程序 Lock 端口 。 锁是一个密钥集 SET NX PX; Lua 脚本发布并仅为持有者扩展.
import { Lock } from '@elysiumjs/olympus';
import { HeraclesModule } from '@elysiumjs/olympus/heracles';
import '@elysiumjs/redis';
HeraclesModule.with({ lock: Lock.for('redis', { connection: 'cache', prefix: 'lock:' }) });
快取存储
KeyvRedis 是一个连接上的 Keyv 商店,用于缓存 @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')
费率限额
RedisRateLimitStore 保留计数器 RateLimit 在Redis, 所以每个实例的应用分享.
赫拉克勒斯语Name
RedisTransport 包含在 Redis 流上的队列任务. HeraclesRedisModule 添加两个命令: heracles:work 经营一个消耗排队量的工人 heracles:clean 从溪流中删除已完成的工作.
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
流量
RedisFlowStore 保持流动 @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:' })
});
每道流都是散列 {prefix}{flow:flowKey},其租赁密钥将自行失效,一旦流量完成,则该标记将保持其所有者和TTL的结束时间。 流键共享散列标记,所以它们生活在同一个集群槽上.
会议
RedisSessionStore 保存会议 @elysiumjs/olympus/themis在任何连接上,上层包括:
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:' })
}
});
每个会话都是 JSON 值 {prefix}{id} (单位:千美元)session: 页:1.
许可证
阿帕奇 - 2.0