Back to Redis

LPUSHX

content/commands/lpushx.md

latest1.2 KB
Original Source

Inserts specified values at the head of the list stored at key, only if key already exists and holds a list. In contrary to [LPUSH]({{< relref "/commands/lpush" >}}), no operation will be performed when key does not yet exist.

Examples

{{% redis-cli %}} LPUSH mylist "World" LPUSHX mylist "Hello" LPUSHX myotherlist "Hello" LRANGE mylist 0 -1 LRANGE myotherlist 0 -1 {{% /redis-cli %}}

Redis Software and Redis Cloud compatibility

| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | |

Return information

{{< multitabs id="lpushx-return-info" tab1="RESP2" tab2="RESP3" >}}

Integer reply: the length of the list after the push operation.

-tab-sep-

Integer reply: the length of the list after the push operation.

{{< /multitabs >}}