w3resource

Redis Lists: LPUSHX

LPUSHX key value

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

Syntax:

LPUSHX KEY_NAME VALUE1.. VALUEN     

Available since

2.2.0.

Return Value

Integer replies the length of the list after the push operations.

Return Value Type

Integer

Example: Redis LPUSHX

127.0.0.1:6379> LPUSH mycolor1 white
(integer) 1
127.0.0.1:6379> LPUSHX mycolor1 black
(integer) 2
127.0.0.1:6379> LPUSHX mycolor1 red
(integer) 3
127.0.0.1:6379> LPUSHX mycolor2 blue
(integer) 0

The key mycolor2 not exists, so return 0

127.0.0.1:6379> EXISTS mycolor2
(integer) 0
127.0.0.1:6379> LRANGE mycolor1 0 -1
1) "red"
2) "black"
3) "white"

Previous: LPUSH
Next: LREM



Follow us on Facebook and Twitter for latest update.