Rig.TUnit.Caching.Redis
0.1.0-beta.2
dotnet add package Rig.TUnit.Caching.Redis --version 0.1.0-beta.2
NuGet\Install-Package Rig.TUnit.Caching.Redis -Version 0.1.0-beta.2
<PackageReference Include="Rig.TUnit.Caching.Redis" Version="0.1.0-beta.2" />
<PackageVersion Include="Rig.TUnit.Caching.Redis" Version="0.1.0-beta.2" />
<PackageReference Include="Rig.TUnit.Caching.Redis" />
paket add Rig.TUnit.Caching.Redis --version 0.1.0-beta.2
#r "nuget: Rig.TUnit.Caching.Redis, 0.1.0-beta.2"
#:package Rig.TUnit.Caching.Redis@0.1.0-beta.2
#addin nuget:?package=Rig.TUnit.Caching.Redis&version=0.1.0-beta.2&prerelease
#tool nuget:?package=Rig.TUnit.Caching.Redis&version=0.1.0-beta.2&prerelease
Rig.TUnit.Caching.Redis
Redis-as-cache fixture (primary home for
RedisFixture) withRedisBackplaneCapturefor pub/sub cache-invalidation tests.
What this package is
The Rig.TUnit Redis-as-cache provider. Primary home for RedisFixture —
the same container is re-used by Rig.TUnit.Databases.NoSql.Redis in
its KV role. Exposes UseRedisCache(…) (no bare UseRedis — ADR-007
forces the caller to declare intent cache vs KV). Ships
RedisBackplaneCapture which subscribes to a pub/sub channel and
records cache-invalidation events, so tests can assert
"publishing orders:cache-invalidate evicts the L1 on every node".
When to use it
- Testing distributed-cache coherency with pub/sub-based invalidation.
- L2 backing for FusionCache / HybridCache distributed-tier tests.
- Asserting cache hit-rate targets against real Redis.
- Not for: KV-store scenarios — use
Rig.TUnit.Databases.NoSql.Redis.
Prerequisites
- .NET 10 SDK
- Docker Desktop / Colima (Redis image ~120 MB)
StackExchange.Redis(transitive)
Quick start
using Rig.TUnit.Caching.Redis.Fixtures;
using StackExchange.Redis;
await using var fx = new RedisFixture();
await fx.InitializeAsync();
var db = ConnectionMultiplexer.Connect(fx.ConnectionString).GetDatabase();
await db.StringSetAsync("cache:orders:42", "{}", TimeSpan.FromMinutes(5));
Options
| Property | Type | Default | Description |
|---|---|---|---|
Image |
string |
"redis:7-alpine" |
Image |
StartupTimeoutSeconds |
int |
30 |
Redis boots fast |
Password |
string? |
null |
Off in dev mode |
BackplaneChannel |
string |
"cache-invalidate" |
Pub/sub channel |
Fixture + helper APIs
Rig.TUnit.Caching.Redis.Fixtures.RedisFixtureRig.TUnit.Caching.Redis.Options.RedisCacheFixtureOptionsRig.TUnit.Caching.Redis.Builder.RedisCacheRigBuilderRig.TUnit.Caching.Redis.Helpers.RedisBackplaneCapture
Per-test isolation
Per-test key prefix cache:{IsolationKey:short}:*. Teardown via
SCAN + DEL on the prefix. Pub/sub channels are per-fixture to avoid
cross-test subscriber leakage.
Parallelism + performance
- First-run pull: ~5 s.
- Warm startup: ~1 s.
- Per-op Get/Set: ~150 µs (in-process latency dominated).
- Parallelism: 8+ concurrent tests — key-prefix isolation makes this trivially safe.
Troubleshooting
TimeoutExceptionon first op —ConnectionMultiplexer.Connectis synchronous and blocks until the initial topology discovery completes; under heavy parallel startup this can exceed the default 5-second timeout. RaiseSyncTimeoutin your config.- Backplane capture missed events —
ISubscriber.Subscribeis eventually-consistent; poll for the subscription to be active before publishing (fixture does this but a custom wire-up must too).
See docs/troubleshooting.md#redis-cache.
Provider quirks + edge cases
- Redis pub/sub is fire-and-forget — a subscriber started after a publish misses the message. Always subscribe before triggering the event the test expects.
KEYS *is the classic production foot-gun; the fixture-internal teardown usesSCAN(O(1) per batch) instead.- Cache-vs-KV split rationale: ADR-007. Bare
UseRedisdoes not exist; this is deliberate.
Benchmarks
See RedisCacheBenchmarks.cs;
baseline in benchmarks/baseline-005.json.
Related docs
- ADR-007 — Redis cache/KV split
- Architecture diagram
- Glossary
- Family base:
Rig.TUnit.Caching - Sibling:
Rig.TUnit.Databases.NoSql.Redis
License
MIT. See LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- Bogus (>= 35.6.1)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
- Microsoft.Extensions.TimeProvider.Testing (>= 10.0.0)
- Rig.TUnit.Caching (>= 0.1.0-beta.2)
- StackExchange.Redis (>= 2.8.22)
- Testcontainers (>= 4.11.0)
- Testcontainers.Redis (>= 4.11.0)
- TUnit.Core (>= 1.34.5)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Rig.TUnit.Caching.Redis:
| Package | Downloads |
|---|---|
|
Rig.TUnit.All
Meta-package containing every Rig.TUnit.* package. DISCOURAGED — prefer per-feature or per-stack meta-packages (Rig.TUnit, Rig.TUnit.Microservices). |
|
|
Rig.TUnit.Databases.NoSql.Redis
TUnit fixture for Redis-as-database backed by Testcontainers. Use for Redis-as-database scenarios; for caching see Rig.TUnit.Caching.Redis. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-beta.2 | 42 | 4/27/2026 |
| 0.0.0-alpha.0.14 | 44 | 4/26/2026 |