Galosys.Foundation.RulesEngine.Redis 26.5.20.1

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

Galosys.Foundation.RulesEngine.Redis

规则引擎 Redis Pub/Sub 热更新广播模块,支持多实例部署时规则变更的跨实例同步通知。

依赖: Galosys.Foundation.RulesEngine(必选)+ Galosys.Foundation.Redis(必选)

快速开始

1. 注册服务

// Program.cs
services.AddRuleEngine(configuration);
services.AddRedisRuleChangeNotifier(configuration);

需先注册 Redis 实现(FreeRedis 或 StackExchange.Redis):

services.AddFreeRedis(configuration);   // 或 services.AddStackExchangeRedis(configuration);
services.AddRuleEngine(configuration);
services.AddRedisRuleChangeNotifier(configuration);

2. 配置

{
  "Rules": {
    "Redis": {
      "Channel": "rules:change"
    }
  }
}
配置项 默认值 说明
Rules:Redis:Channel "rules:change" Pub/Sub 频道名

3. 发布变更通知

管理后台修改规则后,通知所有实例刷新缓存:

public class RuleAdminController : ControllerBase
{
    private readonly RuleChangePublisher _publisher;

    public RuleAdminController(RuleChangePublisher publisher)
    {
        _publisher = publisher;
    }

    /// <summary>
    /// 通知所有实例刷新指定规则集
    /// </summary>
    [HttpPost("rules/{ruleSet}/refresh")]
    public async Task<IActionResult> RefreshRules(string ruleSet)
    {
        await _publisher.PublishAsync(ruleSet);
        return Ok();
    }
}

工作原理

实例 A (修改规则) ──publish──▶ Redis (rules:change channel)
                                      │
                          ┌───────────┼───────────┐
                          ▼           ▼           ▼
                       实例 A      实例 B      实例 C
                    (清缓存)    (清缓存)    (清缓存)
  • RedisRuleChangeListener 监听 Redis Pub/Sub 消息
  • 收到消息后调用 RuleSetCache.Remove(精准刷新)或 Clear()(全量刷新)
  • RuleChangePublisher 发布变更通知,供管理后台调用

消息格式

{
  "RuleSet": "discount",
  "Type": "Updated"
}
字段 说明
RuleSet 规则集名称(为空则全量刷新)
Type 变更类型:Added/Updated/Removed/Reloaded
Product 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 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
26.5.20.1 96 5/20/2026
26.5.19.1 96 5/19/2026
26.5.18.1 92 5/18/2026
26.5.15.1 95 5/15/2026
26.5.12.3 94 5/12/2026
26.5.12.2 96 5/12/2026