Mud.Feishu.Redis
1.2.0
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Mud.Feishu.Redis --version 1.2.0
NuGet\Install-Package Mud.Feishu.Redis -Version 1.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mud.Feishu.Redis" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mud.Feishu.Redis" Version="1.2.0" />
<PackageReference Include="Mud.Feishu.Redis" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Mud.Feishu.Redis --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Mud.Feishu.Redis, 1.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Mud.Feishu.Redis@1.2.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Mud.Feishu.Redis&version=1.2.0
#tool nuget:?package=Mud.Feishu.Redis&version=1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Mud.Feishu.Redis
飞书事件订阅组件 Redis 分布式去重扩展。
功能特性
- 事件去重: 基于 EventId 的分布式去重,防止重复处理同一事件
- Nonce 去重: 防止重放攻击,确保请求的唯一性
- SeqID 去重: WebSocket 二进制消息序列号去重,防止重复处理
- 原子性操作: 使用 Redis SETNX + EXPIRE 确保去重操作的原子性
- 自动过期: Redis 自动清理过期数据,无需手动维护
- 分布式支持: 适用于多实例部署场景
安装
dotnet add package Mud.Feishu.Redis
快速开始
配置 Redis 连接
在 appsettings.json 中添加配置:
{
"Feishu": {
"Redis": {
"ConnectionString": "localhost:6379",
"EventCacheExpiration": "24:00:00",
"NonceTtl": "00:05:00",
"SeqIdCacheExpiration": "24:00:00",
"EventKeyPrefix": "feishu:event:",
"NonceKeyPrefix": "feishu:nonce:",
"SeqIdKeyPrefix": "feishu:seqid:",
"ConnectTimeout": 5000,
"SyncTimeout": 5000,
"Ssl": false,
"AllowAdmin": true
}
}
}
注册服务
注册所有去重服务
using Mud.Feishu.Redis.Extensions;
// 自动从配置文件读取 Redis 连接信息并注册所有去重服务
builder.Services
.AddFeishuRedis()
.AddFeishuRedisDeduplicators();
单独注册服务
// 只注册事件去重服务
builder.Services
.AddFeishuRedis()
.AddFeishuRedisEventDeduplicator();
// 只注册 Nonce 去重服务
builder.Services
.AddFeishuRedis()
.AddFeishuRedisNonceDeduplicator();
// 只注册 SeqID 去重服务
builder.Services
.AddFeishuRedis()
.AddFeishuRedisSeqIDDeduplicator();
完整示例
var builder = WebApplication.CreateBuilder(args);
// 注册 Redis 服务(从配置文件读取)
builder.Services
.AddFeishuRedis()
.AddFeishuRedisDeduplicators()
.AddFeishuWebSocket(options =>
{
options.AppId = builder.Configuration["Feishu:AppId"];
options.AppSecret = builder.Configuration["Feishu:AppSecret"];
});
var app = builder.Build();
app.Run();
配置选项
RedisOptions 配置项
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
ConnectionString |
string | "localhost:6379" | Redis 连接字符串 |
EventCacheExpiration |
TimeSpan | 24小时 | 事件去重缓存过期时间 |
NonceTtl |
TimeSpan | 5分钟 | Nonce 有效期 |
SeqIdCacheExpiration |
TimeSpan | 24小时 | SeqID 去重缓存过期时间 |
EventKeyPrefix |
string | "feishu:event:" | 事件去重键前缀 |
NonceKeyPrefix |
string | "feishu:nonce:" | Nonce 去重键前缀 |
SeqIdKeyPrefix |
string | "feishu:seqid:" | SeqID 去重键前缀 |
ConnectTimeout |
int | 5000ms | 连接超时时间 |
SyncTimeout |
int | 5000ms | 同步超时时间 |
Ssl |
bool | false | 是否启用 TLS/SSL |
AllowAdmin |
bool | true | 是否允许管理员操作 |
Redis 数据结构
事件去重
- Key:
{keyPrefix}{eventId} - Type: String
- Value: "1"
- TTL: 由
cacheExpiration指定
Nonce 去重
- Key:
{keyPrefix}{nonce} - Type: String
- Value: "1"
- TTL: 由
nonceTtl指定
SeqID 去重
- Key:
{keyPrefix}{seqId} - Type: String
- Value: "1"
- TTL: 由
cacheExpiration指定 - Sorted Set:
{keyPrefix}set(用于记录已处理的 SeqID)
常见问题
1. 如何更改默认的缓存过期时间?
在配置文件中修改:
{
"Feishu": {
"Redis": {
"EventCacheExpiration": "7.00:00:00",
"NonceTtl": "00:10:00",
"SeqIdCacheExpiration": "7.00:00:00"
}
}
}
2. 多个环境如何隔离数据?
通过配置文件设置不同的键前缀:
开发环境 appsettings.Development.json:
{
"Feishu": {
"Redis": {
"EventKeyPrefix": "dev:feishu:event:",
"NonceKeyPrefix": "dev:feishu:nonce:",
"SeqIdKeyPrefix": "dev:feishu:seqid:"
}
}
}
生产环境 appsettings.Production.json:
{
"Feishu": {
"Redis": {
"EventKeyPrefix": "prod:feishu:event:",
"NonceKeyPrefix": "prod:feishu:nonce:",
"SeqIdKeyPrefix": "prod:feishu:seqid:"
}
}
}
3. 如何监控 Redis 去重状态?
每个去重服务都提供了日志记录,可以通过日志查看去重状态:
// 获取已处理的事件数量
var deduplicator = serviceProvider.GetRequiredService<IFeishuEventDistributedDeduplicator>();
var count = await deduplicator.GetCachedCountAsync();
4. 如何使用 TLS/SSL 连接 Redis?
在配置文件中启用 SSL:
{
"Feishu": {
"Redis": {
"ConnectionString": "secure.redis.com:6380,password=xxx",
"Ssl": true
}
}
}
或使用 rediss:// 协议:
{
"Feishu": {
"Redis": {
"ConnectionString": "rediss://secure.redis.com:6380"
}
}
}
许可证
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.1)
- Microsoft.Extensions.Http (>= 8.0.1)
- Microsoft.Extensions.Http.Polly (>= 8.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- Microsoft.Extensions.Options (>= 8.0.2)
- Mud.Feishu.Abstractions (>= 1.2.0)
- StackExchange.Redis (>= 2.10.1)
- System.Text.Json (>= 10.0.2)
-
net10.0
- Microsoft.Extensions.Configuration.Binder (>= 10.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.2)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.1)
- Microsoft.Extensions.Http (>= 10.0.2)
- Microsoft.Extensions.Http.Polly (>= 10.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.2)
- Microsoft.Extensions.Options (>= 10.0.2)
- Mud.Feishu.Abstractions (>= 1.2.0)
- StackExchange.Redis (>= 2.10.1)
-
net6.0
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.1)
- Microsoft.Extensions.Http (>= 8.0.1)
- Microsoft.Extensions.Http.Polly (>= 8.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- Microsoft.Extensions.Options (>= 8.0.2)
- Mud.Feishu.Abstractions (>= 1.2.0)
- StackExchange.Redis (>= 2.10.1)
-
net8.0
- Microsoft.Extensions.Configuration.Binder (>= 10.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.2)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 10.0.1)
- Microsoft.Extensions.Http (>= 10.0.2)
- Microsoft.Extensions.Http.Polly (>= 10.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.2)
- Microsoft.Extensions.Options (>= 10.0.2)
- Mud.Feishu.Abstractions (>= 1.2.0)
- StackExchange.Redis (>= 2.10.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 3.0.0-preview3 | 94 | 5/22/2026 | |
| 3.0.0-preview2 | 118 | 5/11/2026 | |
| 3.0.0-preview1 | 149 | 5/1/2026 | |
| 2.1.3 | 152 | 5/22/2026 | |
| 2.1.2 | 128 | 5/12/2026 | |
| 2.1.1 | 107 | 5/11/2026 | |
| 2.1.0 | 123 | 5/1/2026 | |
| 2.0.9 | 180 | 4/24/2026 | |
| 2.0.8 | 156 | 4/12/2026 | |
| 2.0.7 | 160 | 4/7/2026 | |
| 2.0.6 | 113 | 4/5/2026 | |
| 2.0.5 | 202 | 3/28/2026 | |
| 2.0.4 | 138 | 3/19/2026 | |
| 2.0.3 | 119 | 2/26/2026 | |
| 2.0.2 | 122 | 1/30/2026 | |
| 2.0.1 | 118 | 1/27/2026 | |
| 1.2.2 | 144 | 1/19/2026 | |
| 1.2.1 | 145 | 1/16/2026 | |
| 1.2.0 | 165 | 1/14/2026 | |
| 1.1.2 | 138 | 1/11/2026 |