Show / Hide Table of Contents

Class DbContextBase

Base class that implements the interface with the methods responsible for connect at Redis server and management of Id administration.

Inheritance
System.Object
DbContextBase
Implements
IDbContext
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ToString()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: StoneCo.Framework.Data.Redis.Contexts
Assembly: cs.temp.dll.dll
Syntax
public class DbContextBase : IDbContext

Constructors

DbContextBase(IOptionsSnapshot<RedisOptions>)

Default constructor that set the RedisOptions.

Declaration
public DbContextBase(IOptionsSnapshot<RedisOptions> options)
Parameters
Type Name Description
IOptionsSnapshot<RedisOptions> options

Options object

Examples

note

This is an initial configuration that should be used as a basis for the following examples.

First let's create the model that will represent the model within the context.

using StoneCo.Framework.Model;
public class Foo : IModel
{
    public Foo(long id, string content, bool done)
    {
        Id = id;
        Content = content;
        Done = done;
    }

    public long Id { get; private set; }
    public string Content { get; private set; }
    public bool Done { get; private set; }
}

Here we have the appsettings.json structure.

Fields "Host" and "Collection" are required on file appsettings.json.

{
   "Redis": {
       "Host": "stoneco.redis",
       "Port": "6379",
       "DataBase": "0",
       "Password": "stone@2019",
       "Collection":"FooParent"
   }
}

Dependency injection of configuration on ServiceCollection

using StoneCo.Framework.Data.Redis;

string appSettingsRedisOptions = "Redis";

services.Configure<RedisOptions>(options => configuration.GetSection(appSettingsRedisOptions).Bind(options));

Loading the information from the configuration file above.

var configuration = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json", false)
    .Build();

Loading information for dependency injection.

services.AddScoped<IDbContext, DbContextBase>();

Properties

Database

Database field.

Declaration
public IDatabase Database { get; }
Property Value
Type Description
IDatabase

Instance of StackExchange.Redis.IDatabase object.

PartialIdsNamespace

Partial namespace Ids field.

Declaration
public string PartialIdsNamespace { get; }
Property Value
Type Description
System.String

String formatted like '$"Collections:IDs:{RedisOptions.Collection}:"'.

PartialNamespace

Partial namespace field.

Declaration
public string PartialNamespace { get; }
Property Value
Type Description
System.String

String formatted like '$"Collections:{RedisOptions.Collection}:'.

Methods

GetKeys(String, Int32)

Go to redis and get keys of a uri.

Declaration
public IEnumerable<RedisKey> GetKeys(string pattern, int quantity)
Parameters
Type Name Description
System.String pattern

Pattern string to naviagate on URI.

System.Int32 quantity

Max Number of itens that will be returned.

Returns
Type Description
System.Collections.Generic.IEnumerable<RedisKey>

List of StackExchange.Redis.RedisKey object.

Examples
var keys = DbContext.GetKeys(DbContext.PartialNameSpace + "*", quantity);
Exceptions
Type Condition
System.ArgumentException

Pattern parameter should have a value.

System.ArgumentOutOfRangeException

Quantity parameter must be more than zero.

Implements

IDbContext
Back to top Generated by DocFX