w3resource

Redis Lists: RPUSHX

RPUSHX key value

Redis RPUSHX command is used to insert a value at the tail of the list stored at key, only if a key already exists and holds a list. In contrary to RPUSH, no operation will be performed when a key does not yet exist.

Syntax:

RPUSHX KEY_NAME VALUE1..VALUEN

Available since

2.2.0.

Return Value

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

Return Value Type

Integer

Example: Redis RPUSHX

127.0.0.1:6379> del mycolor1
(integer) 1
127.0.0.1:6379> RPUSH mycolor1 white
(integer) 1
127.0.0.1:6379> RPUSHX mycolor1 black
(integer) 2
127.0.0.1:6379> RPUSHX mycolor1 red
(integer) 3
127.0.0.1:6379> RPUSHX 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) "white"
2) "black"
3) "red"

Previous: RPUSH
Next: Redis Sets



Follow us on Facebook and Twitter for latest update.