ArielCore.RedisMemory
1.0.2
dotnet add package ArielCore.RedisMemory --version 1.0.2
NuGet\Install-Package ArielCore.RedisMemory -Version 1.0.2
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="ArielCore.RedisMemory" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ArielCore.RedisMemory" Version="1.0.2" />
<PackageReference Include="ArielCore.RedisMemory" />
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 ArielCore.RedisMemory --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ArielCore.RedisMemory, 1.0.2"
#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 ArielCore.RedisMemory@1.0.2
#: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=ArielCore.RedisMemory&version=1.0.2
#tool nuget:?package=ArielCore.RedisMemory&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
使用步骤:
- 首先添加nuget包ArielCore.RedisMemory。并在appsettings.json中添加如下
"RedisConfig": {
"Connection": "192.168.1.136:30379",
"DefaultDatabase": 1,
"InstanceName": ""
}
- 在startup.cs或Program.cs或入口处添加如下
#region 缓存注入
services.Configure<RedisConfigOptions>(_configuration.GetSection("RedisConfig"));
services.AddSingleton<IMemoryCache>(factory =>
{
var cache = new MemoryCache(new MemoryCacheOptions());
return cache;
});
services.AddSingleton<MemoryCacheHelper>();
services.AddSingleton<RedisCacheHelper>();
services.AddSingleton(factory =>
{
Func<string, ICacheHelper> accesor = key =>
{
if (key.Equals(MemoryRedisKey.MemoryName))
{
var mc = factory.GetService<MemoryCacheHelper>();
if (mc == null) throw new ArgumentNullException("MemoryCacheHelper");
return mc;
}
else if (key.Equals(MemoryRedisKey.RedisName))
{
var rc = factory.GetService<RedisCacheHelper>();
if(rc==null) throw new ArgumentNullException("RedisCacheHelper");
return rc;
}
else
{
throw new ArgumentException($"Not Support key : {key}");
}
};
return accesor;
});
#endregion
- 实际使用时候在Service服务中添加类似如下
public class TestService : ITestService
{
private readonly ICacheHelper _memoryCacheHelper;
private readonly ICacheHelper _redisCacheHelper;
private readonly Func<string, ICacheHelper> _serviceCacheAccessor;
public TestService(Func<string, ICacheHelper> serviceCacheAccessor)
{
_serviceCacheAccessor = serviceCacheAccessor;
_memoryCacheHelper = _serviceCacheAccessor("MemoryCacheService");
_redisCacheHelper = _serviceCacheAccessor("RedisCacheService");
}
public string testCache()
{
try
{
_memoryCacheHelper.SetCache("t1", "fef");
_memoryCacheHelper.GetCache<string>(key);
}
catch (Exception e)
{
}
return "";
}
}
| Product | Versions 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 was computed. 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 was computed. 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.
-
net8.0
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Options (>= 10.0.1)
- Newtonsoft.Json (>= 13.0.4)
- StackExchange.Redis (>= 2.10.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.