一键导入
storm-api-redis
Implement Redis caching and pub/sub using the Storm.Api framework with IRedisService for key-value storage, TTL, and channel subscriptions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Implement Redis caching and pub/sub using the Storm.Api framework with IRedisService for key-value storage, TTL, and channel subscriptions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Implement authentication using the Storm.Api framework with JWT, API key, custom authenticators, and refresh tokens. Use when adding auth to endpoints.
Write a database migration using the Storm.Api framework with BaseMigration and OrmLite. Use when creating or modifying database tables, columns, or seed data.
Implement database entities and repositories using the Storm.Api framework with ServiceStack.OrmLite. Use when creating entities, repositories, or database queries.
Implement email sending using the Storm.Api framework with Resend provider and temporary email detection. Use when sending emails or validating email addresses.
Implement a C# endpoint using the Storm.Api framework with CQRS actions, controllers, source generators, exceptions, and response DTOs.
Initialize a new Storm.Api project with NuGet packages, Program.cs, Startup.cs, and code style configuration. Use when setting up a new project from scratch.
| name | storm-api-redis |
| description | Implement Redis caching and pub/sub using the Storm.Api framework with IRedisService for key-value storage, TTL, and channel subscriptions. |
| user-invocable | true |
| disable-model-invocation | false |
You are helping implement Redis caching and pub/sub using the Storm.Api framework. Follow all patterns below exactly. For global rules (logging, extensions, anti-patterns), see /storm-api.
The user's request: $ARGUMENTS
Storm.Api wraps StackExchange.Redis behind an IRedisService interface providing key-value storage with TTL and pub/sub messaging. The connection is lazy (created on first use) and thread-safe.
{
"Redis": {
"Endpoints": ["localhost:6379"],
"User": "default",
"Password": "your-password",
"DefaultDatabase": 0,
"ConnectTimeout": 5000,
"ConnectRetry": 3,
"ClientName": "my-app",
"KeepAliveSeconds": 60,
"AbortOnConnectFail": false,
"ChannelPrefix": "myapp:"
}
}
Required: Endpoints, User, Password. All other properties are optional with sensible defaults. See RedisConfiguration class for full details.
using Storm.Api.Redis;
var redisConfig = configuration.GetSection("Redis").LoadRedisConfiguration();
services.AddSingleton(redisConfig);
services.AddSingleton<IRedisService, RedisService>();
Use IRedisService inside any action or service via Resolve<IRedisService>():
var redis = Resolve<IRedisService>();
// Set with TTL
await redis.SetAsync("user:123:name", "Alice", TimeSpan.FromMinutes(30));
await redis.SetAsync("user:123:avatar", bytes, TimeSpan.FromHours(1));
// Get
string? name = await redis.GetStringAsync("user:123:name");
byte[]? data = await redis.GetBytesAsync("user:123:avatar");
// Get and delete atomically (useful for one-time tokens)
string? token = await redis.GetAndDeleteAsync("reset-token:abc123");
// Delete
bool deleted = await redis.DeleteAsync("user:123:name");
// Publish
await redis.PublishAsync("events:user-created", userId.ToString());
// Subscribe (typically in a background worker)
await using var subscription = await redis.SubscribeAsync("events:user-created");
await foreach (string message in subscription.Read(cancellationToken))
{
// Process each message
}
RedisSubscription implements IAsyncDisposable — always use await using. It automatically unsubscribes when enumeration ends or is cancelled.
For a complete caching-in-action example, see examples/caching.md. For a pub/sub background worker example, see examples/pubsub-worker.md.
/storm-api-queues) — no external dependency needed.| ❌ Wrong | ✅ Correct |
|---|---|
Create ConnectionMultiplexer manually | Register IRedisService as singleton via DI |
Use StackExchange.Redis types directly in actions | Use IRedisService abstraction |
| Subscribe in an action (short-lived scope) | Subscribe in a hosted service (long-lived) |
| Store objects without serialization | Serialize to string/bytes before storing |