redis Adding Items to a List


Redis allows you to add items to either the right or the left of a list.

If I was working with a list, my_list and I wanted to prepend 3 to the list, I could do that using the Redis LPUSH command:

LPUSH my_list 3

If I wanted to append 3 to my_list, I would instead use the RPUSH command:

RPUSH my_list 3

Both the LPUSH and RPUSH command will automatically create a new list for you if the supplied key doesn't exist. Two alternative commands LPUSHX and RPUSHX can be used to only operate on the list key if it already exists.