Redis - List Lpushx Command



Redis LPUSHX command inserts the value at the head of the list stored at the key, only if the key already exists and holds a list.

Return Value

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

Syntax

Following is the basic syntax of Redis LPUSHX command.

redis 127.0.0.1:6379> LPUSHX KEY_NAME VALUE1.. VALUEN

Example

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