Apq.Cfg.Redis
1.2.1
dotnet add package Apq.Cfg.Redis --version 1.2.1
NuGet\Install-Package Apq.Cfg.Redis -Version 1.2.1
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="Apq.Cfg.Redis" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Apq.Cfg.Redis" Version="1.2.1" />
<PackageReference Include="Apq.Cfg.Redis" />
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 Apq.Cfg.Redis --version 1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Apq.Cfg.Redis, 1.2.1"
#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 Apq.Cfg.Redis@1.2.1
#: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=Apq.Cfg.Redis&version=1.2.1
#tool nuget:?package=Apq.Cfg.Redis&version=1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Apq.Cfg.Redis
Redis 配置源扩展包。
仓库地址:https://gitee.com/apq/Apq.Cfg
📖 在线文档:https://apq-cfg.vercel.app/
依赖
- Apq.Cfg
- StackExchange.Redis 2.10.1
默认层级
该配置源的默认层级为 CfgSourceLevels.Redis (100)。
如果不指定 level 参数,将使用默认层级:
// 使用默认层级 100
.AddRedis(options => { ... })
// 指定自定义层级
.AddRedis(options => { ... }, level: 150)
用法
using Apq.Cfg;
using Apq.Cfg.Redis;
var cfg = new CfgBuilder()
.AddRedis(options =>
{
options.ConnectionString = "localhost:6379";
options.KeyPrefix = "config:";
}, level: 1, isPrimaryWriter: true)
.Build();
// 使用索引器访问
var connStr = cfg["Database:ConnectionString"];
var timeout = cfg.GetValue<int>("Database:Timeout");
方法签名
public static CfgBuilder AddRedis(
this CfgBuilder builder,
Action<RedisOptions> configure,
int level = CfgSourceLevels.Redis, // 默认 100
bool isPrimaryWriter = false)
RedisOptions
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
ConnectionString |
string? |
- | Redis 连接字符串 |
KeyPrefix |
string? |
- | 键前缀,用于过滤配置键 |
Database |
int? |
null | Redis 数据库索引 |
Channel |
string? |
- | 发布/订阅通道,配置变更时发送通知 |
ConnectTimeoutMs |
int |
5000 | 连接超时(毫秒) |
OperationTimeoutMs |
int |
5000 | 操作超时(毫秒) |
ScanPageSize |
int |
250 | SCAN 命令每次返回的键数量 |
示例
基本配置
.AddRedis(options =>
{
options.ConnectionString = "localhost:6379";
}, level: 0)
带前缀和通道
.AddRedis(options =>
{
options.ConnectionString = "localhost:6379,password=secret";
options.KeyPrefix = "myapp:config:";
options.Database = 1;
options.Channel = "config-updates";
}, level: 1, isPrimaryWriter: true)
数据存储
配置以 Redis String 类型存储:
SET config:Database:ConnectionString "Server=localhost"
SET config:Logging:Level "Information"
读取时使用 SCAN 命令按前缀扫描所有键。
许可证
MIT License
作者
- 邮箱:amwpfiqvy@163.com
仓库
- Gitee:https://gitee.com/apq/Apq.Cfg
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. net10.0 is compatible. 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.
-
net10.0
- Apq.Cfg (>= 1.2.1)
- StackExchange.Redis (>= 2.10.1)
-
net8.0
- Apq.Cfg (>= 1.2.1)
- StackExchange.Redis (>= 2.10.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.