RetailSolutions.Shared.Cache 1.2.70

There is a newer version of this package available.
See the version list below for details.
dotnet add package RetailSolutions.Shared.Cache --version 1.2.70
                    
NuGet\Install-Package RetailSolutions.Shared.Cache -Version 1.2.70
                    
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="RetailSolutions.Shared.Cache" Version="1.2.70" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RetailSolutions.Shared.Cache" Version="1.2.70" />
                    
Directory.Packages.props
<PackageReference Include="RetailSolutions.Shared.Cache" />
                    
Project file
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 RetailSolutions.Shared.Cache --version 1.2.70
                    
#r "nuget: RetailSolutions.Shared.Cache, 1.2.70"
                    
#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 RetailSolutions.Shared.Cache@1.2.70
                    
#: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=RetailSolutions.Shared.Cache&version=1.2.70
                    
Install as a Cake Addin
#tool nuget:?package=RetailSolutions.Shared.Cache&version=1.2.70
                    
Install as a Cake Tool

RetailSolutions.Shared.Cache

Biblioteca de abstrações para Redis com suporte a distributed locks usando RedLock.net.

Instalação

dotnet add package RetailSolutions.Shared.Cache

Ou via Package Manager Console:

Install-Package RetailSolutions.Shared.Cache

Uso

Configuração Básica

Registre os serviços Redis no seu HostApplicationBuilder:

using RetailSolutions.Shared.Cache;

var builder = Host.CreateApplicationBuilder(args);

var redisConnectionString = builder.Configuration.GetConnectionString("Redis");
builder.AddRedisLock(redisConnectionString, "NomeDaSuaAplicacao");

Configuração no appsettings.json

Adicione a string de conexão do Redis:

{
  "ConnectionStrings": {
    "Redis": "localhost:6379"
  }
}

Para ambientes de produção, você pode incluir autenticação e outras opções:

{
  "ConnectionStrings": {
    "Redis": "servidor:6379,password=senha,ssl=true,abortConnect=false"
  }
}

Serviços Registrados

O método AddRedisLock registra automaticamente:

  • IDistributedLockFactory (singleton) - Factory para criar distributed locks
  • IConnectionMultiplexer (scoped) - Conexão direta com Redis

Exemplo: Usando Distributed Lock

using RedLockNet;

public class ProcessamentoService
{
    private readonly IDistributedLockFactory _lockFactory;

    public ProcessamentoService(IDistributedLockFactory lockFactory)
    {
        _lockFactory = lockFactory;
    }

    public async Task ProcessarRecursoCompartilhado()
    {
        var resource = "recurso-compartilhado";
        var expiryTime = TimeSpan.FromSeconds(30);

        await using var redLock = await _lockFactory.CreateLockAsync(
            resource, 
            expiryTime
        );

        if (redLock.IsAcquired)
        {
            // Lógica crítica executada com lock distribuído
            await ProcessarDados();
        }
        else
        {
            // Lock não adquirido, outro processo está usando o recurso
            throw new InvalidOperationException("Recurso está sendo usado por outro processo");
        }
    }

    private Task ProcessarDados() => Task.CompletedTask;
}

Exemplo: Acesso Direto ao Redis

using StackExchange.Redis;

public class CacheService
{
    private readonly IConnectionMultiplexer _redis;

    public CacheService(IConnectionMultiplexer redis)
    {
        _redis = redis;
    }

    public async Task<string?> ObterValorAsync(string chave)
    {
        var db = _redis.GetDatabase();
        var valor = await db.StringGetAsync(chave);
        return valor.ToString();
    }

    public async Task DefinirValorAsync(string chave, string valor, TimeSpan? expiracao = null)
    {
        var db = _redis.GetDatabase();
        await db.StringSetAsync(chave, valor, expiracao);
    }
}

Dependências

  • Microsoft.Extensions.Configuration (10.0.0)
  • Microsoft.Extensions.DependencyInjection (10.0.0)
  • Microsoft.Extensions.Hosting (10.0.1)
  • RedLock.net (2.3.2)
  • StackExchange.Redis (2.9.25)

Requisitos

  • .NET 10.0 ou superior
  • Instância Redis disponível

Tags

Gemco, RetailSolutions, Redis, Cache, DistributedLock, RedLock

Licença

Copyright © Retail Solutions

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on RetailSolutions.Shared.Cache:

Package Downloads
RetailSolutions.Shared.Jobs

Controle de execução de cronjobs

RetailSolutions.Shared.Max

Abstrações da Max Sistemas

RetailSolutions.Shared.Ifood

Abstrações do Ifood

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.1400 159 7/7/2026
1.3.1370 109 7/6/2026
1.2.122 127 7/6/2026
1.2.107 104 4/30/2026
1.2.90 682 12/13/2025
1.2.89 199 12/13/2025
1.2.84 196 12/13/2025
1.2.73 250 12/12/2025
1.2.70 154 12/12/2025