Starfish.Redis
1.0.6
dotnet add package Starfish.Redis --version 1.0.6
NuGet\Install-Package Starfish.Redis -Version 1.0.6
<PackageReference Include="Starfish.Redis" Version="1.0.6" />
paket add Starfish.Redis --version 1.0.6
#r "nuget: Starfish.Redis, 1.0.6"
// Install Starfish.Redis as a Cake Addin #addin nuget:?package=Starfish.Redis&version=1.0.6 // Install Starfish.Redis as a Cake Tool #tool nuget:?package=Starfish.Redis&version=1.0.6
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 |
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
.
- Open terminal and run
redis-cli
. - Check the current configuration value use
CONFIG GET notify-keyspace-events
. - Set the
notify-keyspace-events
configuration option toAKE
useCONFIG SET notify-keyspace-events AKE
.
Product | Versions 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. net9.0 was computed. 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. |
-
net6.0
- Microsoft.Extensions.Configuration (>= 6.0.0)
- StackExchange.Redis (>= 2.7.33)
-
net7.0
- Microsoft.Extensions.Configuration (>= 7.0.0)
- StackExchange.Redis (>= 2.7.33)
-
net8.0
- Microsoft.Extensions.Configuration (>= 8.0.0)
- StackExchange.Redis (>= 2.7.33)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.