Home > Redis > Redis Learning Note – 05 Command in Redis (List)

Redis Learning Note – 05 Command in Redis (List)

RPUSH key value [value …]
Append one or multiple values at the tail of the list stored at key.
LPUSH key value [value …]
Prepend one or multiple values at the tail of the list stored at key.
LRANGE key start stop
Get a range of elements from a list. The offsets start and stop are zero-based indexes, with 0 being the first element of the list (the head of the list), 1 being the next element and so on, the rightmost item is included.

RPUSH LPUSH LRANGE

RPUSH

RPOP key
Remove and get the last element in a list.
LPOP key
Remove and get the first element in a list.
LPOP RPOP

LTRIM key start stop
Trim a list to the specified range.
LTRIM

 

LINDEX key index
Get an element from a list by its index. The index is zero-based, so 0 means the first element, 1 the second element and so on.
LINDEX

BLPOP key [key …] timeout
It is the blocking version of LPOP because it blocks the connection when there are no elements to pop from any of the given lists.
BRPOP key [key …] timeout
It is the blocking version of RPOP.

If none of the specified keys exist, BLPOP blocks the connection until another client performs an LPUSH or RPUSH operation against one of the keys.
Once new data is present on one of the lists, the client returns with the name of the key unblocking it and the popped value.
When BLPOP causes a client to block and a non-zero timeout is specified, the client will unblock returning a nil multi-bulk value when the specified timeout has expired without a push operation against at least one of the specified keys.
The timeout argument is interpreted as an integer value specifying the maximum number of seconds to block. A timeout of zero can be used to block indefinitely.
BLPOP 1

BLPOP 2

 

RPOPLPUSH source destination
Atomically returns and removes the last element (tail) of the list stored at source, and pushes the element at the first element (head) of the list stored at destination.
BRPOPLPUSH source destination timeout
BRPOPLPUSH is the blocking variant of RPOPLPUSH. When source contains elements, this command behaves exactly like RPOPLPUSH. When source is empty, Redis will block the connection until another client pushes to it or until timeout is reached.
BRPOPLPUSH

 

References:
http://redis.io/commands#list

Categories: Redis
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: