YouTip LogoYouTip

Lists Lpush

Redis Lpush Command

Redis Lpush Command

--

Redis Tutorial

Redis Tutorial Redis Introduction Redis Installation Redis Configuration Redis Data Types

Redis Commands

Redis Commands Redis Keys Redis Strings Redis Hashes Redis Lists Redis Sets Redis Sorted Sets Redis HyperLogLog Redis Pub/Sub Redis Transactions Redis Scripting Redis Connection Redis Server Redis GEO Redis Stream

Redis Advanced Tutorial

Redis Backup and Recovery Redis Security Redis Performance Testing Redis Client Connection Redis Pipelining Redis Partitioning Java Using Redis PHP Using Redis Redis Hashes Redis Sets

Redis Lpush Command

Image 3 Redis Lists

The Redis LPUSH command inserts one or more values at the head of the list. If the key does not exist, an empty list is created before performing the LPUSH operation. When the key exists but is not of list type, an error is returned.

Note: Before Redis version 2.4, the LPUSH command only accepted a single value.

Syntax

The basic syntax of the redis LPUSH command is as follows:

redis 127.0.0.1:6379> LPUSH KEY_NAME VALUE1.. VALUEN

Available Version

>= 1.0.0

Return Value

The length of the list after executing the LPUSH command.

Example

127.0.0.1:6379> LPUSH list1 "foo"
(integer) 1
127.0.0.1:6379> LPUSH list1 "bar"
(integer) 2
127.0.0.1:6379> LRANGE list1 0 -1
1) "bar"
2) "foo"
Image 4 Redis Lists Redis Hashes Redis Sets

ByteArk Coding Plan supports mainstream large models such as Doubao, GLM, DeepSeek, Kimi, MiniMax, etc., directly provided by the official for stable and reliable service. Configuration Guide οΏ₯9.9/month Subscribe Now

← Lists LpushxLists Lpop β†’