Redis-backed distributed cache library. Wraps StackExchange.Redis and
IDistributedCacheinto a singleRedisConnectionvalue that supports both standalone Redis and Redis Sentinel (HA).
paket add Feather.CacheSingle Redis instance — for local development or when HA is not required.
let connection =
Redis.connect (RedisConnectionConfiguration.Standalone {
Instance = Some myInstance // Alma.ServiceIdentification.Instance
Port = 6379
})Three Sentinel nodes managing a primary/replica Redis set. The client always writes to and reads from the current primary — failover is transparent.
In Kubernetes, Sentinel pods expose port 26379. Pod DNS names follow the StatefulSet pattern:
let connection =
Redis.connect (RedisConnectionConfiguration.Sentinel {
Sentinels = [
{ Instance = Some sentinel0Instance; Port = 26379 }
{ Instance = Some sentinel1Instance; Port = 26379 }
{ Instance = Some sentinel2Instance; Port = 26379 }
]
ServiceName = "sentinelName" // must match `sentinel monitor <name>` in sentinel.conf
})All operations are on IDistributedCache via Cache module, or directly on RedisConnection for atomic ops.
open Feather.Cache
// Store with TTL
do! Cache.store connection.Cache (CacheId "my-key") (Some (TimeSpan.FromMinutes 10.0)) "my-value"
// Store without expiry
do! Cache.store connection.Cache (CacheId "my-key") None "my-value"
// Retrieve
let! value = Cache.tryGet connection.Cache (CacheId "my-key")
// value : string optionUse when a value should be consumed exactly once (e.g. one-time tokens).
let! value = connection.GetDelete (CacheId "one-time-token")
// value : string option — atomically removed from RedisStores a plain Redis String (not a Hash), required when the value must also be read by GetDelete.
do! connection.StringSet (CacheId "my-key") (Some (TimeSpan.FromHours 1.0)) "raw-value"IDistributedCache(Cache.store/Cache.tryGet) writes Redis Hashes internally (StackExchange.Redis behaviour).GetDeleteandStringSetoperate on plain Redis Strings and are mutually compatible.- Do not mix
Cache.storewithGetDeleteon the same key — they use different Redis types. - The
RedisConnectionimplementsIDisposable; dispose it on application shutdown.
- Increment version in
Cache.fsproj - Update
CHANGELOG.md - Commit new version and tag it
./build.sh build./build.sh -t tests