redis-set-batch
Set the value of the value field to the key of the key field in a Redis connect profile for each input row.
Syntax
Options
- profile=STRING
- Required. Name of the Redis connect profile. Either a Redis Client (Standalone) or a Redis Client (Sentinel) profile is accepted. Example: profile=my_redis
- key=STRING
- Required. Name of the input field holding the Redis key. Example: key=user_id
- value=STRING
- Required. Name of the input field holding the value to SET. Example: value=name
- ex=INT
- Optional. Expiration time in seconds. An integer of 1 or more. Cannot be used with keep-ttl.
- keep-ttl=BOOL
- Optional. Retain the existing TTL of the key. Specify t. Requires Redis 6.0 or later. Cannot be used with ex.
Input fields
| Field | Type | Required | Description |
|---|---|---|---|
| Field named by the key option | String | Y | Redis key |
| Field named by the value option | String | Y | Value to store. Converted to a string |
Output fields
| Field | Type | Name | Description |
|---|---|---|---|
| _error | String | Error | Error message for SET failure of the row. Absent on success |
All fields of the input row are passed through unchanged; the _error field is added only to rows that failed.
Error codes
Parse errors
| Error message | Cause | Resolution |
|---|---|---|
| No available Redis profile | No profile with the given name exists, or the current account is not granted access to it. | Check the profile name and grant the account access to the profile. |
| profile option is required | The profile option is missing or empty. | Specify profile=profile_name. |
| key option is required | The key option is missing or empty. | Specify key=field_name. |
| value option is required | The value option is missing or empty. | Specify value=field_name. |
| ex option must be a positive integer | The ex value is not an integer or is 0 or less. | Specify an integer of 1 or more. |
| ex and keep-ttl cannot be used together | Both options were specified. | Specify only one of them. |
Runtime errors
| Error message | Cause | Resolution |
|---|---|---|
| (_error field of the output row) | A Redis error occurred while processing the row, such as a connection failure, authentication failure, timeout or WRONGTYPE. The query does not abort; the _error field is added to the row. If the connection fails, every row gets the same error. | Check the message in the _error field, the connection settings and the key type. |
| missing field_name(key) field | The field named by the key option does not exist in the input row. | Check that the input row has the field. |
| missing field_name(value) field | The field named by the value option does not exist in the input row. | Check that the input row has the field. |
Description
For each incoming row, the value of the key field is used as the key and the value of the value field is converted to a string and stored with the Redis SET command. The connection is opened once when the query starts and reused for all rows. Existing values are overwritten.
With ex, the expiration is set with SET EX; with keep-ttl=t, the existing TTL is retained. With neither, the value is stored without expiration and any existing TTL is removed. If a row fails, the query continues and _error is recorded on that row.
Examples
Example: Caching user names
Situation: Store the name of each user ID in Redis for one hour.
json "{}"
| eval user_id="user01", name="Alice"
| redis-set-batch profile=my_redis key=user_id value=name ex=3600
Expected result:
| user_id | name |
|---|---|
| user01 | Alice |
Interpretation: A row without the _error field was stored successfully.