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" />
                    
Directory.Packages.props
<PackageReference Include="RT.MesWeb.Redis" />
                    
Project file
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
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=RT.MesWeb.Redis&version=1.2.0
                    
Install as a Cake Tool

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 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.

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.

Version Downloads Last Updated
1.2.0 132 11/2/2026
1.0.1 276 5/8/2026
1.0.0 160 4/24/2026