Persilsoft.Redis.Caching
1.0.5
dotnet add package Persilsoft.Redis.Caching --version 1.0.5
NuGet\Install-Package Persilsoft.Redis.Caching -Version 1.0.5
<PackageReference Include="Persilsoft.Redis.Caching" Version="1.0.5" />
paket add Persilsoft.Redis.Caching --version 1.0.5
#r "nuget: Persilsoft.Redis.Caching, 1.0.5"
// Install Persilsoft.Redis.Caching as a Cake Addin #addin nuget:?package=Persilsoft.Redis.Caching&version=1.0.5 // Install Persilsoft.Redis.Caching as a Cake Tool #tool nuget:?package=Persilsoft.Redis.Caching&version=1.0.5
Perfilsoft.Redis.Caching
It contains a service for managing a Redis Storage
Example
First, you need to register the required group of services.
using ServiceCollectionExtensions;
Action<RedisCacheOptions> RedisCacheOptionsConfigurator = options =>
builder.Configuration.GetSection("Redis").Bind(options);
builder.Services.AddRedisServices(RedisCacheOptionsConfigurator);
In the configuration file appsettings.json you must configure the following key:
"Redis": {
"Configuration": "localhost:5002",
"InstanceName": "my-redis"
}
Where:
Configuration: The configuration used to connect to Redis.
InstanceName: The Redis instance name.
Now, you can use the IRedisManager service as follows:
Save data
To save information, you need to send a key and its value.
class RedisTest(IRedisManager redisManager)
{
public void Add()
{
await redisManager.SetAsync("myKey", "The value here");
}
}
You can send a value of a complex type, the library will take care of serializing it into a JSON string and storing it.
class RedisTest(IRedisManager redisManager)
{
public async Task Add()
{
var Person1 = new Person("Jhon Doe", 35);
await redisManager.SetAsync("person-1", Person1);
}
}
record class Person(string Name, byte Age);
absoluteExpireTime: Sets an absolute expiration time, relative to now (default: 60 seconds).
unusedExpireTime: Sets how long a cache entry can be inactive (e.g. not accessed) before it will be removed.
This will not extend the entry lifetime beyond the absolute expiration.
await redisManager.SetAsync("person-1", Person1,
absoluteExpireTime: TimeSpan.FromMinutes(2),
unusedExpireTime: TimeSpan.FromSeconds(30));
Retrieve data
You can retrieve the information based on the key.
class RedisTest(IRedisManager redisManager)
{
public async Task PrintValue()
{
var Value = await redisManager.GetAsync("myKey");
Console.WriteLine($"My value is: {Value}");
}
}
If the type stored in Redis is complex, it will need to be deserialized.
class RedisTest(IRedisManager redisManager)
{
public async Task<Person> Get()
{
var Person1 = await redisManager.GetAsync<Person>("person-1");
return Person1;
}
}
Remove data
You can delete information by sending its key.
class RedisTest(IRedisManager redisManager)
{
public async Task Remove()
{
await redisManager.RemoveAsync("person-1");
}
}
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. |
-
net8.0
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Persilsoft.Redis.Caching:
Package | Downloads |
---|---|
Persilsoft.Membership.RefreshTokenService.Redis
Contains a service for managing refresh tokens in Redis for the Membership project |
GitHub repositories
This package is not used by any popular GitHub repositories.