Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Rpush Command

Redis Rpush Command

Redis List

The Redis Rpush command is used to insert one or more values at the tail (rightmost) of the list.

If the list does not exist, an empty list is created and the RPUSH operation is performed. When the list exists but is not of list type, returns an error.

**Note:** Before Redis version 2.4, the RPUSH command only accepted a single value.

Syntax

The basic syntax of the redis Rpush command is as follows:



redis 127.0.0.1:6379> RPUSH KEY_NAME VALUE1..VALUEN

Available Version

= 1.0.0

Return Value

The length of the list after the RPUSH operation.

Example



redis 127.0.0.1:6379> RPUSH mylist "hello"

(integer) 1

redis 127.0.0.1:6379> RPUSH mylist "foo"

(integer) 2

redis 127.0.0.1:6379> RPUSH mylist "bar"

(integer) 3

redis 127.0.0.1:6379> LRANGE mylist 0 -1

1) "hello"

2) "foo"

3) "bar"

Redis List