Easy Tutorial
❮ Lists Rpoplpush Server Bgsave ❯

Redis Lpush Command

Redis Lists

The Redis Lpush command inserts one or more values at the head of a list. If the key does not exist, an empty list is created and the LPUSH operation is performed.

If the key exists but is not a list type, an error is returned.

Note: Prior to version 2.4 of Redis, 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 Versions

= 1.0.0

Return Value

The length of the list after the LPUSH command is executed.

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"

Redis Lists

❮ Lists Rpoplpush Server Bgsave ❯