Persilsoft.Redis.Caching 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Persilsoft.Redis.Caching --version 1.0.4                
NuGet\Install-Package Persilsoft.Redis.Caching -Version 1.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="Persilsoft.Redis.Caching" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Persilsoft.Redis.Caching --version 1.0.4                
#r "nuget: Persilsoft.Redis.Caching, 1.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 Persilsoft.Redis.Caching as a Cake Addin
#addin nuget:?package=Persilsoft.Redis.Caching&version=1.0.4

// Install Persilsoft.Redis.Caching as a Cake Tool
#tool nuget:?package=Persilsoft.Redis.Caching&version=1.0.4                

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
1.0.5 239 10/16/2024
1.0.4 585 7/19/2024
1.0.3 130 5/22/2024
1.0.1 113 4/23/2024
1.0.0 108 4/23/2024