idempotency-handling by aj-geddes/useful-ai-prompts
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill idempotency-handling实现幂等性以确保无论操作执行多少次,都能产生相同的结果。
最小工作示例:
import express from "express";
import Redis from "ioredis";
import crypto from "crypto";
interface IdempotentRequest {
key: string;
status: "processing" | "completed" | "failed";
response?: any;
error?: string;
createdAt: number;
completedAt?: number;
}
class IdempotencyService {
private redis: Redis;
private ttl = 86400; // 24 hours
constructor(redisUrl: string) {
this.redis = new Redis(redisUrl);
}
async getRequest(key: string): Promise<IdempotentRequest | null> {
const data = await this.redis.get(`idempotency:${key}`);
return data ? JSON.parse(data) : null;
}
// ... (完整实现请参阅参考指南)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
references/ 目录下的详细实现:
| 指南 | 内容 |
|---|---|
| Express 幂等性中间件 | Express 幂等性中间件 |
| 基于数据库的幂等性 | 基于数据库的幂等性 |
| Stripe 风格幂等性 | Stripe 风格幂等性 |
| 消息队列幂等性 | 消息队列幂等性 |
每周安装量
106
代码仓库
GitHub 星标数
116
首次出现
2026年1月21日
安全审计
安装于
opencode90
gemini-cli88
codex86
claude-code85
cursor80
github-copilot73
Implement idempotency to ensure operations produce the same result regardless of how many times they're executed.
Minimal working example:
import express from "express";
import Redis from "ioredis";
import crypto from "crypto";
interface IdempotentRequest {
key: string;
status: "processing" | "completed" | "failed";
response?: any;
error?: string;
createdAt: number;
completedAt?: number;
}
class IdempotencyService {
private redis: Redis;
private ttl = 86400; // 24 hours
constructor(redisUrl: string) {
this.redis = new Redis(redisUrl);
}
async getRequest(key: string): Promise<IdempotentRequest | null> {
const data = await this.redis.get(`idempotency:${key}`);
return data ? JSON.parse(data) : null;
}
// ... (see reference guides for full implementation)
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Express Idempotency Middleware | Express Idempotency Middleware |
| Database-Based Idempotency | Database-Based Idempotency |
| Stripe-Style Idempotency | Stripe-Style Idempotency |
| Message Queue Idempotency | Message Queue Idempotency |
Weekly Installs
106
Repository
GitHub Stars
116
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode90
gemini-cli88
codex86
claude-code85
cursor80
github-copilot73
lark-cli 共享规则:飞书资源操作指南与权限配置详解
39,000 周安装
Vercel部署与构建指南:自动化构建流水线、预览部署、发布控制与即时回滚
129 周安装
阿里云CDN OpenAPI自动化操作指南 - 域名管理、缓存刷新、HTTPS证书配置
129 周安装
pnpm 完全指南:JavaScript/TypeScript 包管理器安装、配置与最佳实践
134 周安装
FAISS 向量相似性搜索库 - Meta AI 十亿级向量快速检索,支持 GPU 加速与 Python 集成
130 周安装
Figma设计插件开发与组件系统指南:从自动布局到设计系统管理
130 周安装
tuzi-post-to-x:绕过反机器人检测,自动化发布内容到X/Twitter
70 周安装