Skip to content

Redis write ​

Writes one key to a Redis cache with an expiry: the whole input as JSON, or a text from an expression. Use it to fill a cache, for idempotency (write only if missing) and to share values with C# scripts that use StackExchange.Redis or IDistributedCache.

Pins ​

PinKindTypesDescription
InputinputanyThe record to store (empty Value), and what the expressions read.
Writtencontinuesame as inputThe unchanged input, after the value was stored.
Existsno datasame as inputCondition 1 only: the unchanged input, when the key already existed and nothing was written.

Configuration ​

The configuration is shared with Redis read and Redis delete.

FieldTypeDefaultDescription
ConnectionStringstring (max 2048)Required. StackExchange.Redis configuration string, e.g. redis1:6379,ssl=true,password=...,defaultDatabase=0.
StorageModedropdown: 0 String, 1 DistributedCache00: a plain Redis string (SET). 1: the IDistributedCache hash format (data, absexp, sldexp).
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:{data.OrderId}.
ValuetextText to store, usually an expression such as {data.Token}. Empty: the whole input as JSON.
Ttlinteger (min 0)3600Absolute time to live in seconds. 0: no expiry.
SlidingTtlinteger (min 0)0Visible with StorageMode 1. Sliding expiration in seconds: the entry expires when not read for this long. 0: none.
Conditiondropdown: 0 Always, 1 Only if missing0Visible with StorageMode 0. 1: SET NX, writes only when the key doesn't exist; otherwise the record goes to Exists.

Behaviour ​

  • Key and Value are evaluated for every record: {data.X} is the input, {meta.X} the metadata, {config.X} the flow configuration. An empty key fails that record. Ttl and SlidingTtl are fixed numbers (an expression setting =Package.Setting works, a per-record expression doesn't).
  • Empty Value: the input is stored as JSON written by ViaJsonSerializer (default options, UTF-8), byte for byte what a script writes with ViaJsonSerializer.Serialize. A Value is stored as is (UTF-8 text).
  • 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, an unreachable server or Condition 1 with StorageMode 1 stops the flow at start.
  • A timeout or lost connection fails that record (recoverable error); the next record is tried again.

Notes ​

  • Keys without expiry (Ttl 0) stay until deleted and fill a large cache; choose it deliberately.
  • Condition 1 gives claim-once and idempotency without a lock: the first record writes, the others go to Exists. IDistributedCache has no such call, so it isn't available in DistributedCache mode.
  • To store part of the input as JSON, shape it with the data mapper first and leave Value empty.
  • Keep the password in an expression setting: "ConnectionString": "=Secrets.RedisConnection".

Example ​

Process each order once, across Hosts:

json
{ "ConnectionString": "=Secrets.RedisConnection", "Key": "processed:{data.OrderId}", "Value": "1", "Ttl": 86400, "Condition": 1 }

Kafka consumer → Json deserializer → Redis write ─ Written → process the order; Exists → Log (duplicate)

Viaducta documentation