NewLife.Redis.Extensions
6.5.2026.701
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Core 3.1
This package targets .NET Core 3.1. 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.
dotnet add package NewLife.Redis.Extensions --version 6.5.2026.701
NuGet\Install-Package NewLife.Redis.Extensions -Version 6.5.2026.701
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="NewLife.Redis.Extensions" Version="6.5.2026.701" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NewLife.Redis.Extensions" Version="6.5.2026.701" />
<PackageReference Include="NewLife.Redis.Extensions" />
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 NewLife.Redis.Extensions --version 6.5.2026.701
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NewLife.Redis.Extensions, 6.5.2026.701"
#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 NewLife.Redis.Extensions@6.5.2026.701
#: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=NewLife.Redis.Extensions&version=6.5.2026.701
#tool nuget:?package=NewLife.Redis.Extensions&version=6.5.2026.701
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
NewLife.Redis.Extensions
ASP.NET Core Redis 深度集成扩展
NewLife.Redis.Extensions 是 NewLife.Redis 为 ASP.NET Core 提供的官方集成扩展包,提供 IDistributedCache 分布式缓存、IDataProtection 密钥持久化、DI 自动注入等开箱即用能力。
🆕 本包是旧包
NewLife.Extensions.Caching.Redis(v5.5)的继任者。如果你正在使用旧包,请参阅迁移指引。
功能概览
| 功能 | 说明 |
|---|---|
IDistributedCache |
ASP.NET Core 分布式缓存标准接口实现 |
IDataProtection |
数据保护密钥持久化到 Redis(PersistKeysToRedis) |
| DI 依赖注入 | 一行 AddDistributedRedisCache 自动注册全部服务 |
| 继承 FullRedis | RedisCache 继承 FullRedis,可直接调用全部 Redis 数据结构 |
| 宽框架覆盖 | netcoreapp3.1 / net5.0 ~ net10.0 / netstandard2.0 / netstandard2.1 |
安装
dotnet add package NewLife.Redis.Extensions
快速开始
注册服务
using NewLife.Redis.Extensions;
var builder = WebApplication.CreateBuilder(args);
// 一行注册,自动注入 FullRedis / IDistributedCache / ICache / ICacheProvider
builder.Services.AddDistributedRedisCache(options =>
{
options.Server = "127.0.0.1:6379";
options.Password = "pass";
options.Db = 0;
options.Prefix = "myapp:";
});
使用 IDistributedCache
public class HomeController : Controller
{
private readonly IDistributedCache _cache;
public HomeController(IDistributedCache cache)
{
_cache = cache;
}
public async Task<IActionResult> Index()
{
var value = await _cache.GetStringAsync("greeting");
if (value == null)
{
value = "Hello, Redis!";
await _cache.SetStringAsync("greeting", value,
new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1) });
}
return Content(value);
}
}
使用 FullRedis 完整功能
由于 RedisCache 继承自 FullRedis,注入后可直接使用全部 Redis 数据结构:
public class UserService
{
private readonly FullRedis _redis;
public UserService(FullRedis redis)
{
_redis = redis;
}
public void SaveUser(User user)
{
var list = _redis.GetList<User>("users");
list.Add(user);
var hash = _redis.GetDictionary<String>("user:" + user.Id);
hash["Name"] = user.Name;
hash["Email"] = user.Email;
}
}
数据保护密钥持久化
builder.Services.AddDataProtection()
.PersistKeysToRedis(redis, "DataProtection-Keys");
更多 Redis 操作请参考 NewLife.Redis 主文档。
从旧包迁移
本包是 NewLife.Extensions.Caching.Redis(v5.5)的直接继任者,提供了更好的架构和更多功能:
| 对比项 | NewLife.Extensions.Caching.Redis(旧) | NewLife.Redis.Extensions(新) |
|---|---|---|
| 版本系列 | v5.5 | v6.5+ |
| IDistributedCache | ✅ | ✅ |
| IDataProtection 持久化 | ❌ | ✅ |
| 框架覆盖 | net461; netstandard2.0; netstandard2.1 | netcoreapp3.1 ~ net10.0; netstandard2.0/2.1 |
| RedisCache 基类 | 独立类,包装 FullRedis | 继承 FullRedis,全功能可用 |
| 命名空间 | NewLife.Extensions.Caching.Redis |
NewLife.Redis.Extensions |
迁移步骤:
- 卸载旧包、安装新包
- 更换命名空间:
NewLife.Extensions.Caching.Redis→NewLife.Redis.Extensions - 更换 DI 注册方式:
services.AddRedis(configString)→services.AddDistributedRedisCache(options => {...})
相关链接
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. 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 is compatible. 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 is compatible. 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 is compatible. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .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.
-
.NETCoreApp 3.1
- Microsoft.AspNetCore.DataProtection (>= 3.1.0)
- Microsoft.Extensions.Caching.Abstractions (>= 3.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.9)
- Microsoft.Extensions.Options (>= 10.0.9)
- NewLife.Redis (>= 6.5.2026.701)
-
.NETStandard 2.0
- Microsoft.AspNetCore.DataProtection (>= 6.0.0)
- Microsoft.Extensions.Caching.Abstractions (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- NewLife.Redis (>= 6.5.2026.701)
-
.NETStandard 2.1
- Microsoft.AspNetCore.DataProtection (>= 6.0.0)
- Microsoft.Extensions.Caching.Abstractions (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- NewLife.Redis (>= 6.5.2026.701)
-
net10.0
- Microsoft.AspNetCore.DataProtection (>= 10.0.9)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.9)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.9)
- Microsoft.Extensions.Options (>= 10.0.9)
- NewLife.Redis (>= 6.5.2026.701)
-
net5.0
- Microsoft.AspNetCore.DataProtection (>= 5.0.8)
- Microsoft.Extensions.Caching.Abstractions (>= 5.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Options (>= 5.0.0)
- NewLife.Redis (>= 6.5.2026.701)
-
net6.0
- Microsoft.AspNetCore.DataProtection (>= 6.0.0)
- Microsoft.Extensions.Caching.Abstractions (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- NewLife.Redis (>= 6.5.2026.701)
-
net7.0
- Microsoft.AspNetCore.DataProtection (>= 7.0.0)
- Microsoft.Extensions.Caching.Abstractions (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Options (>= 7.0.0)
- NewLife.Redis (>= 6.5.2026.701)
-
net8.0
- Microsoft.AspNetCore.DataProtection (>= 8.0.28)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options (>= 8.0.2)
- NewLife.Redis (>= 6.5.2026.701)
-
net9.0
- Microsoft.AspNetCore.DataProtection (>= 9.0.17)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.17)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.17)
- Microsoft.Extensions.Options (>= 9.0.17)
- NewLife.Redis (>= 6.5.2026.701)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on NewLife.Redis.Extensions:
| Package | Downloads |
|---|---|
|
CodeRule
业务流水号规则生成器,便于快速生成流水号 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 6.5.2026.701 | 133 | 7/1/2026 |
| 6.5.2026.701-beta1659 | 84 | 7/1/2026 |
| 6.5.2026.701-beta1523 | 76 | 7/1/2026 |
| 6.5.2026.622-beta1600 | 94 | 6/22/2026 |
| 6.5.2026.621-beta1753 | 99 | 6/21/2026 |
| 6.5.2026.601 | 151 | 6/1/2026 |
| 6.5.2026.601-beta0703 | 91 | 6/1/2026 |
| 6.5.2026.501 | 208 | 5/1/2026 |
| 6.5.2026.501-beta0625 | 95 | 5/1/2026 |
| 6.5.2026.420-beta0936 | 105 | 4/20/2026 |
| 6.5.2026.403 | 148 | 4/3/2026 |
| 6.5.2026.403-beta0858 | 112 | 4/3/2026 |
| 6.5.2026.307-beta1435 | 108 | 3/7/2026 |
| 6.5.2026.305-beta0003 | 121 | 3/5/2026 |
| 6.5.2026.303 | 160 | 3/3/2026 |
| 6.5.2026.303-beta0003 | 113 | 3/3/2026 |
| 6.4.2026.215-beta1300 | 119 | 2/15/2026 |
| 6.4.2026.201 | 196 | 2/1/2026 |
| 6.4.2026.201-beta0322 | 117 | 2/1/2026 |
| 6.4.2026.111-beta1644 | 160 | 1/11/2026 |
Loading failed
启用NuGet安全审计,扫描依赖包已知漏洞;添加独立Readme文档,标记旧版扩展包为废弃;增强对不同Redis版本和ACL认证场景的兼容性