IT.Redis.Entity 2.1.2

dotnet add package IT.Redis.Entity --version 2.1.2
NuGet\Install-Package IT.Redis.Entity -Version 2.1.2
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="IT.Redis.Entity" Version="2.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IT.Redis.Entity --version 2.1.2
#r "nuget: IT.Redis.Entity, 2.1.2"
#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 IT.Redis.Entity as a Cake Addin
#addin nuget:?package=IT.Redis.Entity&version=2.1.2

// Install IT.Redis.Entity as a Cake Tool
#tool nuget:?package=IT.Redis.Entity&version=2.1.2

IT.Redis.Entity

NuGet version (IT.Redis.Entity) NuGet pre version (IT.Redis.Entity) GitHub Actions Releases

Object mapping for Redis

Declaring an entity class with mutable keys

    class Document
    {
        private Guid _guid;
        private int _index;

        // Add readonly modifier
#pragma warning disable IDE0044
#pragma warning disable CS0649
        private byte[]? _redisKey;
#pragma warning restore CS0649
#pragma warning restore IDE0044

        private byte _redisKeyBits;

        public byte[]? RedisKey => _redisKey;

        public byte RedisKeyBits => _redisKeyBits;

        public Guid Guid
        {
            get => _guid;
            set
            {
                if (_guid != value)
                {
                    _guid = value;
                    _redisKeyBits |= 1;
                }
            }
        }

        public int Index
        {
            get => _index;
            set
            {
                if (_index != value)
                {
                    _index = value;
                    _redisKeyBits |= 2;
                }
            }
        }

        public string? Name { get; set; }
    }

Init RedisValue formatter

#if NETCOREAPP3_1_OR_GREATER
    var formatter = IT.Redis.Entity.Formatters.JsonFormatter.Default;
#endif

Configuration

var configBuilder = new RedisEntityConfigurationBuilder(formatter);

configBuilder
.Entity<Document>()
.HasKeyPrefix("app:docs")
.HasKey(x => x.Guid)
.HasKey(x => x.Index);

var config = configBuilder.Build();

var reDoc = config.NewEntity<Document>();

Connect to the database redis

var connection = ConnectionMultiplexer.Connect(connectionString);

var db = connection.GetDatabase()!;

New Document and save to redis

var guid = Guid.NewGuid();
var doc = new Document
{
    Guid = guid,
    Index = 1,
    Name = "doc1"
};

db.EntitySet(doc, reDoc);

doc.Index = 2;
doc.Name = "doc2";

db.EntitySet(doc, reDoc);

Load into existing Document

doc.Index = 3;
Assert.That(db.EntityLoad(doc, reDoc), Is.False);
Assert.That(doc.Name, Is.EqualTo("doc2"));

doc.Index = 1;
Assert.That(db.EntityLoad(doc, reDoc), Is.True);
Assert.That(doc.Name, Is.EqualTo("doc1"));

Build redisKey from EntityKeyBuilder

var redisKey = reDoc.KeyBuilder.BuildKey(guid, 1);
Assert.That(redisKey, Is.EqualTo(doc.RedisKey));

Build redisKey from KeyBuilder

var redisKey2 = KeyBuilder.Default.BuildKey("app:docs", guid, 1);
Assert.That(redisKey2, Is.EqualTo(redisKey));

Get Document by redis key

var doc1 = db.EntityGet(redisKey, reDoc);
Assert.That(doc1, Is.Not.Null);
Assert.That(doc1.Name, Is.EqualTo("doc1"));

var redisKey3 = reDoc.KeyBuilder.BuildKey(guid, 3);
var doc3 = db.EntityGet(redisKey3, reDoc);
Assert.That(doc3, Is.Null);

Set global factories

RedisEntity<Document>.Factory = () => reDoc;

RedisEntity.Config = config;
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.2 74 5/22/2024
2.1.1 72 5/22/2024
2.1.1-pre1 73 5/18/2024
2.1.0 69 5/16/2024
2.1.0-pre1 69 5/10/2024
2.0.1 191 12/19/2023
2.0.1-pre1 80 12/19/2023
2.0.0 181 10/30/2023
2.0.0-pre6 102 10/27/2023
2.0.0-pre5 74 10/17/2023
2.0.0-pre4 108 9/26/2023
2.0.0-pre3 78 9/25/2023