Skip to content

Redis read ​

Reads one key from a Redis cache and emits the stored value. Use it for cache lookups, also on keys that C# scripts write with StackExchange.Redis or IDistributedCache.

Pins ​

PinKindTypesDescription
InputinputanyThe record the Key expression reads.
Foundoutputtype of the connectionThe stored value: the JSON deserialized into the connection's type. Viaducta.Plugins.TextPlugin.Types.TextRecord gives the raw stored text (Value) and the key (Name).
NotFoundno datasame as inputThe unchanged input, when the key doesn't exist or has expired.

Configuration ​

The configuration is shared with Redis write and Redis delete; fields marked write only have no effect here.

FieldTypeDefaultDescription
ConnectionStringstring (max 2048)Required. StackExchange.Redis configuration string, e.g. redis1:6379,ssl=true,password=...,defaultDatabase=0.
StorageModedropdown: 0 String, 1 DistributedCache00: plain Redis strings (GET). 1: the IDistributedCache hash format. Must match how the key was written.
InstanceNamestring (max 255)Visible with StorageMode 1. Prefix in front of every key, the RedisCacheOptions.InstanceName of the scripts.
ConnectTimeoutMsinteger (min 1)5000Connect timeout in milliseconds.
SyncTimeoutMsinteger (min 1)5000Timeout of one operation in milliseconds.
CaCertificatecertificate nameCA that signed the server certificate (ssl=true, private CA). Empty: OS trust store.
ClientCertificatecertificate nameClient certificate with private key for mutual TLS.
Keystring (max 1024)Required. The key, usually an expression: order:{config.Env}:{data.CustomerId}.
ValuetextWrite only.
Ttlinteger (min 0)3600Write only.
SlidingTtlinteger (min 0)0Write only.
Conditiondropdown: 0 Always, 1 Only if missing0Write only.

Behaviour ​

  • Key is evaluated for every record: {data.X} is the input, {meta.X} the metadata, {config.X} the flow configuration. An empty key fails that record.
  • The connection is opened at flow start and shared by all Redis components on the Host with the same connection string, timeouts and certificates. A wrong connection string, a missing certificate or an unreachable server stops the flow at start. Later connection losses are reconnected automatically and logged as warnings.
  • In DistributedCache mode a read also refreshes the sliding expiration, as IDistributedCache.GetAsync does.
  • Nothing connected to Found: a found value is not emitted.
  • A value that isn't JSON of the Found type, a timeout or a lost connection fails that record (recoverable error); the next record is tried again.

Notes ​

  • The two storage modes don't read each other's keys: a plain GET on an IDistributedCache entry fails. Values written by other systems that aren't JSON: connect Found as TextRecord.
  • Values are JSON written by ViaJsonSerializer (default options, UTF-8), the serializer the scripts use, so both sides read each other's values.
  • Keep the password in an expression setting: "ConnectionString": "=Secrets.RedisConnection".

Example ​

Cache-aside: read the cache, load and store on a miss. Both branches continue with the same type.

json
{ "ConnectionString": "=Secrets.RedisConnection", "Key": "customer:{data.CustomerId}" }
Input → Redis read ─ Found ─────────────────────────────────────────→ continue
              └──── NotFound → Http client → Json deserializer → Redis write ─ Written → continue

Redis write uses the same Key and an empty Value, so it stores the loaded record and passes it on.

Viaducta documentation