Skip to main content
Use LINSERT to insert an element immediately before or after another element of a list. The pivot is matched by value, and only its first occurrence starting from the head is used. The reply is the new length of the list, 0 when the key does not exist, and -1 when the pivot value was not found, which is how you tell a failed insert from a successful one. Finding the pivot means scanning the list, so this is a linear operation; on long lists it is worth keeping an index elsewhere or using a sorted set instead.

Syntax

Arguments

Response

The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.

Examples

TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.

Related topics

LINSERTOverview