redis-lpush-batch
Push the value of the value field to the head of the Redis list of the key field 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 list key. Example: key=queue
- value=STRING
- Required. Name of the input field holding the value to LPUSH. Example: value=job
Input fields
| Field | Type | Required | Description |
|---|---|---|---|
| Field named by the key option | String | Y | Redis list key |
| Field named by the value option | String | Y | Value to push |
Output fields
| Field | Type | Name | Description |
|---|---|---|---|
| length | Integer | Length | Length of the list after the push |
| _error | String | Error | Error message for LPUSH failure of the row. Absent on success |
All fields of the input row are passed through unchanged, and the length or _error field is added.
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. |
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 value field is converted to a string and pushed to the head of the Redis list named by the key field, and the list length after the push is added as the length field. The connection is opened once when the query starts and reused for all rows.
If the list key does not exist, it is created. For a key of a non-list type, a WRONGTYPE error is recorded in _error of that row and the query continues. Values are stacked at the head in row order, so the latest value ends up first in the list.
Examples
Example: Registering a job in a queue
Situation: Register a job ID in the queue queue:jobs and check the queue length.
json "{}"
| eval queue="queue:jobs", job="job-1003"
| redis-lpush-batch profile=my_redis key=queue value=job
Expected result:
| queue | job | length |
|---|---|---|
| queue:jobs | job-1003 | 1 |
Interpretation: length is the number of elements in the list right after the push.