Giter Club home page Giter Club logo

redis.easyconnectmultiservers's Introduction

Redis.EasyConnectMultiServers

Nuget GitHub Workflow Status Nuget

PTBR Version

Package for ease integration with multiple servers Redis. ๐Ÿ“ฆ

Configuration

  • AddRedisProviderMultiServers: Inject a singleton instance of IRedisProviderMultiServers.
  • IRedisProviderMultiServers Abstraction responsible for provider contracts that operations of CRUD in multiple servers
var configurations = new[]
{
    new RedisConfiguration
    {
        AbortOnConnectFail = true,
        KeyPrefix = "MyPrefix__",
        Hosts = new[] { new RedisHost { Host = "localhost", Port = 6379 } },
        AllowAdmin = true,
        ConnectTimeout = 5000,
        Database = 0,
        PoolSize = 5,
        IsDefault = true
    },
    new RedisConfiguration
    {
        AbortOnConnectFail = true,
        KeyPrefix = "MyPrefix__",
        Hosts = new[] { new RedisHost { Host = "localhost", Port = 6389 } },
        AllowAdmin = true,
        ConnectTimeout = 5000,
        Database = 0,
        PoolSize = 2,
        Name = "Secndary Instance"
    }
};

services.AddRedisProviderMultiServers(configurations);

Exemple of use

public class WeatherForecastController
{
    private readonly IRedisProviderMultiServers _redisProviderMultiServers;

    public WeatherForecastController(IRedisProviderMultiServers redisProviderMultiServers) =>
        _redisProviderMultiServers = redisProviderMultiServers;
}

Write/ Replace

  • Write in all servers configured
await _redisProviderMultiServers.AddAsync(Guid.NewGuid().ToString(), "value");
await _redisProviderMultiServers.ReplaceAsync(Guid.NewGuid().ToString(), "value");
  • Write only in default server: IsDefault = true
await _redisProviderMultiServers.AddDefaultClientAsync(Guid.NewGuid().ToString(), "value");
await _redisProviderMultiServers.ReplaceDefaultClientAsync(Guid.NewGuid().ToString(), "value");

Get

  • The get is performed from the client default: IsDefault = true.
  • The method responds as soon as it finds the key, not continuing with the get on other servers.
await _redisProviderMultiServers.GetAsync<string>(guid.ToString());

Remove

  • Remove in all servers configured
  • Remove only in default server: IsDefault = true
await _redisProviderMultiServers.RemoveAsync(key);
await _redisProviderMultiServers.RemoveDefaultClientAsync(key);

redis.easyconnectmultiservers's People

Contributors

dependabot[bot] avatar wodsonluiz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.