NetPro.RedisManager
6.0.4
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package NetPro.RedisManager --version 6.0.4
NuGet\Install-Package NetPro.RedisManager -Version 6.0.4
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="NetPro.RedisManager" Version="6.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetPro.RedisManager --version 6.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NetPro.RedisManager, 6.0.4"
#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.
// Install NetPro.RedisManager as a Cake Addin #addin nuget:?package=NetPro.RedisManager&version=6.0.4 // Install NetPro.RedisManager as a Cake Tool #tool nuget:?package=NetPro.RedisManager&version=6.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
RedisManager使用
同时支持StackExchangeRedis和CsRedis,支持分布式锁 不推荐使用此库,Redis请使用指定客户端实现的 NetPro.CsRedis、NetPro.StackExchange.Redis或者原生CsRedis
appsetting.json
"RedisCacheOption": {
"Enabled": true,//是否开启
"RedisComponent": -1,//-1:NullRedis;1:CSRedis;2:StackExchangeRedis
"Password": "netpro",
"IsSsl": false,
"Preheat": 20,//预热
"Cluster": true, //集群模式
"ConnectionTimeout": 20,
"Endpoints": [
{
"Port": 6665,
"Host": "192.168.66.33"
},
{
"Port": 6666,
"Host": "192.168.66.66"
}
],
"Database": 0,
"DefaultCustomKey": "",
"PoolSize": 50
},
使用
启用redis服务
//新增redis缓存注入
if (configuration.GetValue<bool>("RedisCacheOption:Enabled",false))//是否开启redis
services.AddRedisManager(configuration);
构造函数注入
public class WeatherForecastController : ControllerBase
{
private readonly IRedisManager _redisManager;
/// <summary>
///
/// </summary>
/// <param name="redisManager"></param>
public WeatherForecastController(
IRedisManager redisManager)
{
_redisManager = redisManager;
}
}
方法说明
/// <summary>
/// 获取缓存,没有则新增缓存
/// 不过期或者过期时间时间大于一小时,数据将缓存到本地内存
/// 过期时间等于-1(永不过期)的缓存无法覆盖更新,建议删除后新增
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key">缓存健值,建议key最少三段以:分割便于的管理</param>
/// <param name="func">缓存不存在要执行的委托</param>
/// <param name="expiredTime">过期时间,单位秒</param>
/// <returns></returns>
T GetOrCreate<T>(string key, Func<T> func = null, int expiredTime -1);
方法中调用
//同步方法
var result = _redisManager.GetOrCreate<string>("1",func: ()=>//获取key的值,没有找到则执行委托并将委托返回的值插入redis缓存
{
return "1";
},500);
//异步方法
var resultAsync = await _redisManager.GetOrCreateAsync<string>("1",func: ()=>//获取key的值,没有找到则执行委托并将委托返回的值插入redis缓存
{
return "1";
});
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | 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.
-
.NETStandard 2.1
- CSRedisCore (>= 3.6.8)
- Microsoft.Extensions.Caching.Memory (>= 6.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- RedLock.net (>= 2.3.1)
- StackExchange.Redis (>= 2.2.88)
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 |
---|---|---|
6.0.16 | 202 | 7/24/2023 |
6.0.15 | 416 | 7/19/2022 |
6.0.14 | 428 | 7/10/2022 |
6.0.13 | 404 | 6/15/2022 |
6.0.12 | 413 | 6/15/2022 |
6.0.11 | 411 | 6/15/2022 |
6.0.10 | 420 | 6/11/2022 |
6.0.9 | 409 | 6/8/2022 |
6.0.8 | 422 | 5/26/2022 |
6.0.8-beta.3 | 124 | 5/24/2022 |
6.0.8-beta.2 | 123 | 5/24/2022 |
6.0.7 | 449 | 5/18/2022 |
6.0.6 | 438 | 4/28/2022 |
6.0.5 | 418 | 3/30/2022 |
6.0.5-beta.20 | 115 | 4/27/2022 |
6.0.5-beta.19 | 125 | 4/25/2022 |
6.0.5-beta.18 | 117 | 4/22/2022 |
6.0.5-beta.17 | 124 | 4/16/2022 |
6.0.5-beta.16 | 138 | 4/8/2022 |
6.0.5-beta.15 | 127 | 4/8/2022 |
6.0.5-beta.14 | 131 | 4/7/2022 |
6.0.5-beta.13 | 137 | 4/7/2022 |
6.0.5-beta.12 | 126 | 4/6/2022 |
6.0.5-beta.11 | 135 | 4/6/2022 |
6.0.5-beta.10 | 132 | 3/31/2022 |
6.0.5-beta.9 | 138 | 3/26/2022 |
6.0.5-beta.8 | 132 | 3/22/2022 |
6.0.5-beta.7 | 125 | 3/21/2022 |
6.0.5-beta.6 | 122 | 3/14/2022 |
6.0.5-beta.5 | 126 | 3/2/2022 |
6.0.5-beta.4 | 127 | 2/22/2022 |
6.0.5-beta.3 | 139 | 2/18/2022 |
6.0.5-beta.2 | 130 | 2/18/2022 |
6.0.5-beta.1 | 129 | 2/16/2022 |
6.0.4 | 477 | 2/10/2022 |
6.0.3 | 461 | 2/9/2022 |
6.0.3-beta.9 | 130 | 2/10/2022 |
6.0.3-beta.7 | 141 | 1/27/2022 |
6.0.3-beta.6 | 139 | 1/19/2022 |
6.0.3-beta.5 | 143 | 1/17/2022 |
6.0.3-beta.4 | 147 | 1/16/2022 |
6.0.3-beta.3 | 133 | 1/14/2022 |
6.0.3-beta.2 | 142 | 1/13/2022 |
6.0.3-beta.1 | 161 | 1/11/2022 |
6.0.2 | 324 | 1/6/2022 |
6.0.1 | 932 | 12/3/2021 |
3.1.11 | 339 | 11/19/2021 |
3.1.10 | 443 | 7/29/2021 |
3.1.9 | 370 | 7/1/2021 |
3.1.8 | 1,758 | 12/15/2020 |
3.1.6 | 1,896 | 9/16/2020 |
3.1.5 | 1,674 | 9/8/2020 |
3.1.3 | 1,804 | 6/30/2020 |
3.1.2 | 1,811 | 6/23/2020 |
3.1.1 | 1,925 | 5/26/2020 |
3.1.0 | 3,007 | 5/24/2020 |
1.0.1 | 2,010 | 5/4/2020 |
1.0.0 | 1,788 | 4/27/2020 |