Santel.RedisModule 0.1.0

Suggested Alternatives

Santel.Redis.TypedKeys

dotnet add package Santel.RedisModule --version 0.1.0
                    
NuGet\Install-Package Santel.RedisModule -Version 0.1.0
                    
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="Santel.RedisModule" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Santel.RedisModule" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Santel.RedisModule" />
                    
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 Santel.RedisModule --version 0.1.0
                    
#r "nuget: Santel.RedisModule, 0.1.0"
                    
#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 Santel.RedisModule@0.1.0
                    
#: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=Santel.RedisModule&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Santel.RedisModule&version=0.1.0
                    
Install as a Cake Tool

Santel.RedisModule

High-level .NET (net9.0) helper around StackExchange.Redis that:

  • Auto-initializes strongly-typed RedisKey<T> (string keys) and RedisHashKey<T> (hash keys) defined as properties on your context class.
  • Adds optional in-memory caching per key / hash field.
  • Publishes change notifications (Pub/Sub) for individual fields or whole-hash updates.
  • Wraps values with metadata (UTC timestamp + Persian date string) using RedisDataWrapper<T>.
  • Provides batched bulk read/write helpers & size (MEMORY USAGE) inspection.

Install

(When published to NuGet)

 dotnet add package Santel.RedisModule

Or via PackageReference:

<PackageReference Include="Santel.RedisModule" Version="0.1.0" />

Core Types

Type Purpose
RedisDBContextModule Reflection bootstrapper: finds RedisKey<> / RedisHashKey<> properties and wires them up.
RedisKey<T> Simple string key with optional in-memory cache + publish callback.
RedisHashKey<T> Hash key abstraction with per-field cache, bulk ops, size limiting (default 4000 fields).
RedisDataWrapper<T> Adds timestamp + Persian formatted date around stored data.

Quick Start

public class MyRedisContext : RedisDBContextModule
{
    // Will be auto-initialized (Db 0)
    public RedisKey<string> AppConfig { get; set; } = new(0);

    // Hash of user profiles (Db 1)
    public RedisHashKey<UserProfile> Users { get; set; } = new(1);

    public MyRedisContext(ILogger<MyRedisContext> logger,
                          IConnectionMultiplexer writer,
                          IConnectionMultiplexer reader,
                          string env,
                          bool cache = true)
        : base(logger, writer, reader, env, cache, usePushNotification: true) { }
}

// Usage (e.g. in a scoped service)
var ctx = new MyRedisContext(logger, writerMux, readerMux, "Prod", keepDataInMemory: true);

// String key
ctx.AppConfig.Write("v1.2.3");
var version = ctx.AppConfig.Read();

// Hash key write & read
ctx.Users.Write("42", new UserProfile { Id = 42, Name = "Alice" });
var user = ctx.Users.Read("42");

// Bulk write
await ctx.Users.WriteAsync(usersDictionary, forceToPublish: true);

// Paged hash field names (cursor-based approximation)
var (keys, total) = await ctx.GetHashKeysByPage(1, ctx.Users.FullName, pageNumber: 2, pageSize: 25);
public record UserProfile(int Id, string Name)
{
    public UserProfile() : this(0, "") { }
}

Pub/Sub Notifications

Each key/hash publishes to a channel named after the environment (e.g. Prod).

  • RedisKey<T> publishes: KeyName
  • RedisHashKey<T> publishes: HashName|field or HashName|all (bulk write)

Subscribe example:

var sub = readerMux.GetSubscriber();
await sub.SubscribeAsync("Prod", (channel, message) =>
{
    // Parse messages like: Users|all  or Users|42  or AppConfig
});

Caching Behavior

Set keepDataInMemory=true in the context constructor to enable:

  • RedisKey<T> caches the last wrapper.
  • RedisHashKey<T> caches individual field wrappers on first read. Use ForceToReFetch() / ForceToReFetchAll() to invalidate.

Size & Limits

  • RedisHashKey<T> refuses writes if current + incoming fields exceed 4000 (guard). Adjust in source if needed.
  • GetSize() uses Redis MEMORY USAGE (approximate, may require proper permissions / Redis version >= 4).

Custom Serialization

Provide lambdas when constructing a key/hash:

public RedisHashKey<MyType> Items { get; set; } = new(2,
    serialize: v => JsonConvert.SerializeObject(v, customSettings),
    deSerialize: s => JsonConvert.DeserializeObject<MyType>(s, customSettings)!);

You still receive the wrapping metadata via RedisDataWrapper<T>.

Thread Safety Notes

  • Hash per-field cache uses ConcurrentDictionary.
  • Single key cache uses a lock object.
  • Bulk write uses chunking (maxChunkSizeInBytes) to avoid very large payloads.

Extending

  • Add new RedisKey<> / RedisHashKey<> properties to your derived context.
  • Optionally expose domain-specific helpers around raw read/write calls.

Testing Concurrency

RedisHashKey<int>.TestConcurrency_IN_ForceToReFetchAll stress-tests cache invalidation vs. parallel reads.

Logging

All operations log errors with the provided ILogger to aid diagnostics.

Roadmap Ideas

  • Configurable max hash length.
  • Optional compression layer.
  • Strongly typed pub/sub eventing helpers.

License

MIT (add LICENSE file if not present).


Generated README based on project source.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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

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
0.1.0 137 10/4/2025 0.1.0 is deprecated because it is no longer maintained.