Open sandboxFocus

Property ReadCommandFlags

ReadCommandFlags

Gets or sets the Redis StackExchange.Redis.CommandFlags for read-only operations. The default value is null, which means StackExchange.Redis.CommandFlags.PreferMaster when the Redis backend has an in-memory L1 layer, and StackExchange.Redis.CommandFlags.PreferReplica otherwise.

Declaration
public CommandFlags? ReadCommandFlags { get; init; }
Property Value
Type Description
CommandFlags?
Remarks

A Redis replica receives the write operations of the master asynchronously. A read operation that is sent to a replica can therefore return an item that has just been removed or invalidated, and it can fail to return an item that has just been stored. Without an L1 layer, this inconsistency ends when the replica has received the write operation, so read operations are sent to a replica by default.

With an L1 layer, which is added by the WithL1(OutOfProcessCachingBackendBuilder, LayeredCachingBackendConfiguration?) method, the item that a read operation returns is copied into the in-memory cache of the application instance. An item that is read from a replica after its removal would stay in the in-memory cache until it expires there or until it is removed or invalidated again. Read operations are therefore sent to the master by default.

Setting this property to StackExchange.Redis.CommandFlags.PreferReplica for a backend with an L1 layer is supported. The application must then tolerate that an application instance returns a removed or invalidated item for as long as that item stays in the in-memory cache of the instance.

A stand-alone RedisCacheDependencyGarbageCollector has no L1 layer, so it uses StackExchange.Redis.CommandFlags.PreferReplica when this property is null.