Starfish.Redis 1.0.3

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

// Install Starfish.Redis as a Cake Tool
#tool nuget:?package=Starfish.Redis&version=1.0.3

Microsoft.Extensions.Configuration.Redis

Redis configuration provider implementation for Microsoft.Extensions.Configuration.

Redis key/value

The Redis configuration provider requires a hash key in Redis. The following example shows how to store json settings to Redis hash structure.

Note: The Redis configuration provider does not support nested values.

Origin json data

{
  "Settings": {
    "Server": "localhost",
    "Database": "master",
    "Ports": [ "1433", "1434", "1435" ]
  }
}

The Redis key/value pair structure is shown below.

Redis key: appsettings

Redis value:

Settings:Server = localhost
Settings:Database = master
Settings:Ports:0 = 1433
Settings:Ports:1 = 1434
Settings:Ports:2 = 1435

How to?

The following example shows how to read application settings from the Redis.

Install NuGet package

NuGet package:

Package Version Downloads
Starfish.Redis Nuget Nuget
Install-Package Starfish.Redis
dotnet add package Starfish.Redis
<PackageReference Include="Starfish.Redis" Version="$(StarfishVersion)" />

Add Redis configuration provider

using System;
using Microsoft.Extensions.Configuration;

class Program
{
    static void Main()
    {
        IConfiguration config = new ConfigurationBuilder()
            .AddRedis("127.0.0.1:6379,ssl=False,allowAdmin=True,abortConnect=False,defaultDatabase=0,connectTimeout=500,connectRetry=3", "appsettings")
            .Build();

        // Get a configuration section
        IConfigurationSection section = config.GetSection("Settings");

        // Read simple values
        Console.WriteLine($"Server: {section["Server"]}");
        Console.WriteLine($"Database: {section["Database"]}");

        // Read a collection
        Console.WriteLine("Ports: ");
        IConfigurationSection ports = section.GetSection("Ports");

        foreach (IConfigurationSection child in ports.GetChildren())
        {
            Console.WriteLine(child.Value);
        }
    }
}

Enable Redis Keyspace Notifications

The Redis configuration provider uses Redis keyspace notifications to invalidate the cache when the configuration changes. The Redis keyspace notifications are disabled by default. To enable the Redis keyspace notifications, set the notify-keyspace-events configuration option in the Redis configuration file to AKE.

  1. Open terminal and run redis-cli.
  2. Check the current configuration value use CONFIG GET notify-keyspace-events.
  3. Set the notify-keyspace-events configuration option to AKE use CONFIG SET notify-keyspace-events AKE.
Product Compatible and additional computed target framework versions.
.NET 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. 
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
1.0.3 100 3/6/2024
1.0.2 132 12/23/2023
1.0.1 101 12/22/2023
1.0.0 75 12/21/2023