Lzq.Extensions.Redis 0.0.8

There is a newer version of this package available.
See the version list below for details.
dotnet add package Lzq.Extensions.Redis --version 0.0.8
                    
NuGet\Install-Package Lzq.Extensions.Redis -Version 0.0.8
                    
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="Lzq.Extensions.Redis" Version="0.0.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lzq.Extensions.Redis" Version="0.0.8" />
                    
Directory.Packages.props
<PackageReference Include="Lzq.Extensions.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 Lzq.Extensions.Redis --version 0.0.8
                    
#r "nuget: Lzq.Extensions.Redis, 0.0.8"
                    
#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 Lzq.Extensions.Redis@0.0.8
                    
#: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=Lzq.Extensions.Redis&version=0.0.8
                    
Install as a Cake Addin
#tool nuget:?package=Lzq.Extensions.Redis&version=0.0.8
                    
Install as a Cake Tool

Lzq.Extensions.Redis

基于 FreeRedis 的 .NET 8 轻量级 Redis 封装库。

⚙️ 配置 (appsettings.json)

{
  "Redis": {
    "Prefix": "Lzq:",
    "ConnectionString": "127.0.0.1:6379",
    "IsCluster": false,
    "Sentinels": []
  }
}

🛠️ 注册服务

builder.Services.AddLzqRedis(builder.Configuration);

💡 核心用法

1. 分布式锁 (RAII 模式)

使用 using 自动管理锁生命周期,确保异常时安全释放。

using (_redis.Lock("resource_key", 10))
{
    // 互斥业务逻辑
}

2. 高级缓存 (GetOrSetAsync)

一行代码解决:缓存击穿(并发锁)穿透(空值处理)和雪崩(随机过期)

var data = await _redis.GetOrSetAsync(
    "user_info", 
    async () => await _db.Users.GetAsync(id), 
    TimeSpan.FromHours(1)
);

3. 基础操作

await _redis.SetAsync("key", value, TimeSpan.FromMinutes(10));
var val = await _redis.GetAsync<string>("key");
await _redis.RemoveAsync("key");

💎 核心优势

  • 集群适配:自动处理 Hash Tag {},支持 Redis Cluster。
  • 类型安全:基于 .NET 8 强类型 Options 验证。
  • 健壮重试:内置指数退避逻辑,缓解高并发锁竞争压力。

⚠️ 提示

  • Lock 失败会抛出异常,业务层需捕获。
  • 所有 Key 自动带前缀:Prefix:{key}
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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.2.0 53 5/19/2026
0.0.9 59 5/17/2026
0.0.8 63 5/17/2026
0.0.5 63 5/17/2026