NewLife.Redis.Extensions
6.6.2026.801
See the version list below for details.
dotnet add package NewLife.Redis.Extensions --version 6.6.2026.801
NuGet\Install-Package NewLife.Redis.Extensions -Version 6.6.2026.801
<PackageReference Include="NewLife.Redis.Extensions" Version="6.6.2026.801" />
<PackageVersion Include="NewLife.Redis.Extensions" Version="6.6.2026.801" />
<PackageReference Include="NewLife.Redis.Extensions" />
paket add NewLife.Redis.Extensions --version 6.6.2026.801
#r "nuget: NewLife.Redis.Extensions, 6.6.2026.801"
#:package NewLife.Redis.Extensions@6.6.2026.801
#addin nuget:?package=NewLife.Redis.Extensions&version=6.6.2026.801
#tool nuget:?package=NewLife.Redis.Extensions&version=6.6.2026.801
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. |
-
.NETCoreApp 3.1
- Microsoft.AspNetCore.DataProtection (>= 10.0.10)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.10)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Options (>= 10.0.10)
- NewLife.Redis (>= 6.6.2026.801)
-
.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.6.2026.801)
-
.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.6.2026.801)
-
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.6.2026.801)
-
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.6.2026.801)
-
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.6.2026.801)
-
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.6.2026.801)
-
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.6.2026.801)
-
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.6.2026.801)
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.6.2026.805-beta0751 | 72 | 8/5/2026 |
| 6.6.2026.801 | 117 | 8/1/2026 |
| 6.6.2026.801-beta1800 | 81 | 8/1/2026 |
| 6.5.2026.713-beta0858 | 121 | 7/13/2026 |
| 6.5.2026.701 | 685 | 7/1/2026 |
| 6.5.2026.701-beta1659 | 107 | 7/1/2026 |
| 6.5.2026.701-beta1523 | 99 | 7/1/2026 |
| 6.5.2026.622-beta1600 | 110 | 6/22/2026 |
| 6.5.2026.621-beta1753 | 112 | 6/21/2026 |
| 6.5.2026.601 | 168 | 6/1/2026 |
| 6.5.2026.601-beta0703 | 103 | 6/1/2026 |
| 6.5.2026.501 | 219 | 5/1/2026 |
| 6.5.2026.501-beta0625 | 105 | 5/1/2026 |
| 6.5.2026.420-beta0936 | 116 | 4/20/2026 |
| 6.5.2026.403 | 158 | 4/3/2026 |
| 6.5.2026.403-beta0858 | 121 | 4/3/2026 |
| 6.5.2026.307-beta1435 | 119 | 3/7/2026 |
| 6.5.2026.305-beta0003 | 133 | 3/5/2026 |
| 6.5.2026.303 | 168 | 3/3/2026 |
| 6.5.2026.303-beta0003 | 122 | 3/3/2026 |
优化RedisCache异步实现,真异步支持取消;新增RedLock/Search等回归测试;修复测试硬编码Redis地址问题;升级Microsoft.Extensions依赖