NetPro.StackExchange.Redis 6.0.16

dotnet add package NetPro.StackExchange.Redis --version 6.0.16
NuGet\Install-Package NetPro.StackExchange.Redis -Version 6.0.16
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.StackExchange.Redis" Version="6.0.16" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetPro.StackExchange.Redis --version 6.0.16
#r "nuget: NetPro.StackExchange.Redis, 6.0.16"
#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.StackExchange.Redis as a Cake Addin
#addin nuget:?package=NetPro.StackExchange.Redis&version=6.0.16

// Install NetPro.StackExchange.Redis as a Cake Tool
#tool nuget:?package=NetPro.StackExchange.Redis&version=6.0.16

RedisManager使用

支持 StackExchange.Redis,支持分布式锁。 redisjson参考:redisjson

appsetting.json


"RedisConfiguration": {
		"Enabled": true,
		"KeyPrefix": "net:",
		"Hosts": [
			{
				"Host": "185.56.167.565",
				"Port": 6379
			}
		],
		"ConnectTimeout": 1000,
		"Database": 0,
		"Password": "666666",
		"ssl": false
	}

使用

启用redis服务
  public void ConfigureServices(IServiceCollection services)
  {
    //新增redis缓存注入
   services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(configuration);
  }
构造函数注入
public class WeatherForecastController : ControllerBase
{
        private readonly IRedisDatabase _redisDatabase;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="redisManager"></param>
        public WeatherForecastController(
            IRedisDatabase redisDatabase)
        {
            _redisDatabase_ = redisDatabase;
        }
}

方法说明
 /// <summary>
 ///获取或者创建缓存 
 /// localExpiredTime参数大于0并且小于expiredTime数据将缓存到本地内存
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="key"></param>
 /// <param name="func"></param>
 /// <param name="expiredTime">redis过期时间,默认不过期</param>
 /// <param name="localExpiredTime">本地过期时间,0 默认本地不缓存单位秒</param>
 /// <returns></returns>
 T GetOrSet<T>(string key, Func<T> func = null, TimeSpan? expiredTime = null, int localExpiredTime = 0);
方法中调用

//同步方法
 var result = _redisDatabase_.GetOrCreate<string>("1",func: ()=>//获取key的值,没有找到则执行委托并将委托返回的值插入redis缓存
 {
     return "1";
 },TimeSpan.FromeSecond(66));


//异步方法
  var resultAsync = await _redisDatabase_.GetOrCreateAsync<string>("1",func: async()=>//获取key的值,没有找到则执行委托并将委托返回的值插入redis缓存
 {
     return await Task.FromResult("1") ;
 });
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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 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.1 is compatible. 
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
6.0.16 139 7/24/2023
6.0.15 383 7/19/2022
6.0.14 424 7/10/2022
6.0.13 390 6/15/2022
6.0.12 370 6/15/2022
6.0.11 388 6/15/2022
6.0.10 391 6/11/2022
6.0.9 390 6/8/2022
6.0.8 391 5/26/2022
6.0.8-beta.3 98 5/24/2022
6.0.8-beta.2 101 5/24/2022
6.0.7 387 5/18/2022
6.0.6 401 4/28/2022
6.0.5 383 3/30/2022
6.0.5-beta.20 107 4/27/2022
6.0.5-beta.19 104 4/25/2022
6.0.5-beta.18 109 4/22/2022
6.0.5-beta.17 107 4/16/2022
6.0.5-beta.16 106 4/8/2022
6.0.5-beta.15 106 4/8/2022
6.0.5-beta.14 117 4/7/2022
6.0.5-beta.13 116 4/7/2022
6.0.5-beta.12 113 4/6/2022
6.0.5-beta.11 108 4/6/2022
6.0.5-beta.10 110 3/31/2022
6.0.5-beta.9 119 3/26/2022
6.0.5-beta.8 108 3/22/2022
6.0.5-beta.7 102 3/21/2022
6.0.5-beta.6 109 3/14/2022
6.0.5-beta.5 108 3/2/2022
6.0.5-beta.4 109 2/22/2022
6.0.5-beta.3 111 2/18/2022
6.0.5-beta.2 109 2/18/2022
6.0.5-beta.1 111 2/16/2022
6.0.4 410 2/10/2022
6.0.3 402 2/9/2022
6.0.3-beta.9 110 2/10/2022
6.0.3-beta.7 125 1/27/2022
6.0.3-beta.6 120 1/19/2022
6.0.3-beta.5 122 1/17/2022
6.0.3-beta.4 124 1/16/2022
6.0.3-beta.3 122 1/14/2022
6.0.3-beta.2 122 1/13/2022
6.0.3-beta.1 153 1/11/2022
6.0.2 296 1/6/2022
6.0.1 899 12/3/2021
3.1.11 290 11/17/2021
3.1.10 370 7/29/2021
3.1.9 345 7/1/2021
3.1.8 390 12/15/2020