Redis - List Lpush Command



Redis LPUSH command inserts all the specified values at the head of the list stored at the key. If the key does not exist, it is created as an empty list before performing the push operations. When the key holds a value that is not a list, an error is returned.

Return Value

Integer reply, the length of the list after the push operations.

Syntax

Following is the basic syntax of Redis LPUSH command.

redis 127.0.0.1:6379> LPUSH KEY_NAME VALUE1.. VALUEN

Example

redis 127.0.0.1:6379> LPUSH list1 "foo" 
(integer) 1 
redis 127.0.0.1:6379> LPUSH list1 "bar" 
(integer) 2 
redis 127.0.0.1:6379> LRANGE list1 0 -1 
1) "foo" 
2) "bar"
redis_lists.htm
Advertisements