RT.MesWeb.Redis
1.2.0
dotnet add package RT.MesWeb.Redis --version 1.2.0
NuGet\Install-Package RT.MesWeb.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="RT.MesWeb.Redis" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RT.MesWeb.Redis" Version="1.2.0" />
<PackageReference Include="RT.MesWeb.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 RT.MesWeb.Redis --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: RT.MesWeb.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 RT.MesWeb.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=RT.MesWeb.Redis&version=1.2.0
#tool nuget:?package=RT.MesWeb.Redis&version=1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Redis 使用说明
安装
dotnet add package RT.MesWeb.Redis
目标框架:net8.0 / net10.0
配置要求
配置节固定为 Redis(RedisOptions.Position):
{
"Redis": {
"ConnectionString": "127.0.0.1:6379,password=123456,abortConnect=false",
"DBIndex": 0
}
}
| 配置项 | 必填 | 默认值 | 说明 |
|---|---|---|---|
ConnectionString |
是 | 无 | StackExchange.Redis 连接串。缺失或空白时,ConfigureRedis 在启动注册阶段直接抛 InvalidOperationException |
DBIndex |
否 | 0 |
写入 ConfigurationOptions.DefaultDatabase,连接产生的 IDatabase 默认都使用该库 |
使用说明
在应用构建前注册配置与服务:
services.ConfigureRedis(configuration);
ConfigureRedis 会注册:
IOptions<RedisOptions>IConnectionMultiplexer单例(注册阶段即执行ConnectionMultiplexer.Connect)RedisService单例AddLocalization()(RedisService依赖IStringLocalizer,幂等,不会覆盖宿主已有配置)
业务代码注入 RedisService,通过 Db 属性获取 IDatabase 操作数据:
public class SessionStore
{
private readonly IDatabase _db;
public SessionStore(RedisService redis)
{
_db = redis.Db;
}
public Task SaveAsync(string key, string value) =>
_db.StringSetAsync(key, value, TimeSpan.FromMinutes(20));
}
注意事项
- 数据库索引用
DBIndex配置:本包会在解析连接串后统一覆盖DefaultDatabase,连接串里即使写了defaultDatabase=也会被DBIndex覆盖。 - 连接是同步建立的:首次解析
IConnectionMultiplexer/RedisService时会阻塞到连接结果。建议连接串带abortConnect=false,避免 Redis 短暂不可用时启动直接失败(连接恢复事件会记录日志)。 - 不要重复注册:
IConnectionMultiplexer与RedisService都由本包注册为单例,宿主不要再注册自己的 multiplexer,否则会出现两套连接池。 - 不封装数据操作方法:直接暴露
IDatabase,批处理、事务、Lua 脚本等能力均可直接使用,本包只负责连接生命周期与连接事件日志。 - 连接事件日志:连接失败 / 恢复 / 内部错误会通过
ILogger<RedisService>记录,文案来自RT.MesWeb.Redis.Resources.SharedResource。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0 && < 11.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0 && < 11.0.0)
- Microsoft.Extensions.Localization (>= 8.0.0 && < 11.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0 && < 11.0.0)
- StackExchange.Redis (>= 2.10.1 && < 3.0.0)
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0 && < 11.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0 && < 11.0.0)
- Microsoft.Extensions.Localization (>= 8.0.0 && < 11.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0 && < 11.0.0)
- StackExchange.Redis (>= 2.10.1 && < 3.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on RT.MesWeb.Redis:
| Package | Downloads |
|---|---|
|
RT.MesWeb.Authentication
Authentication server for mes system |
GitHub repositories
This package is not used by any popular GitHub repositories.