Skip to content

Lists & Hashes: Overview

This module introduces two of Redis’s most useful data structures: Lists and Hashes.

A List is an ordered collection of strings backed by a doubly-linked list. You can push and pop elements from either end in O(1) time — no matter how many items are in the list. That makes lists ideal for queues, stacks, activity feeds, and recent-item trackers.

A Hash is a field-value map stored under a single key — think of it as a Python dict or a JavaScript object. You can set and get individual fields atomically, which means you can update a user’s email without touching any of their other attributes.

127.0.0.1:6379> RPUSH notifications "login" "purchase" "logout"
(integer) 3
127.0.0.1:6379> LRANGE notifications 0 -1
1) "login"
2) "purchase"
3) "logout"
127.0.0.1:6379> HSET user:1 name "Ada" email "[email protected]" age "30"
(integer) 3
127.0.0.1:6379> HGETALL user:1
1) "name"
2) "Ada"
3) "email"
5) "age"
6) "30"
TypeUse when you need…Examples
ListOrdered elements, O(1) head/tail accessMessage queues, activity feeds, recent searches
HashNamed fields on one key, partial updatesUser profiles, product records, session data
LessonTopic
Lists & Hashes: OverviewThis page — Lists, Hashes, when to use each
ListsLPUSH, RPUSH, LRANGE, LLEN, LINDEX, LSET, LREM, LTRIM
Lists as Queues & StacksLPUSH+RPOP (FIFO), LPUSH+LPOP (stack), BLPOP/BRPOP
HashesHSET, HGET, HMGET, HGETALL, HDEL, HEXISTS, HKEYS, HVALS, HLEN
Hash ObjectsModeling objects, HINCRBY, HINCRBYFLOAT, HSETNX

Try pushing items onto a list and storing fields in a hash:

127.0.0.1:6379> RPUSH tasks "write tests" "deploy" "notify team"
(integer) 3
127.0.0.1:6379> LRANGE tasks 0 -1
1) "write tests"
2) "deploy"
3) "notify team"
127.0.0.1:6379> HSET product:99 name "Widget" price "9.99" stock "100"
(integer) 3
127.0.0.1:6379> HGET product:99 name
"Widget"
127.0.0.1:6379> HGET product:99 price
"9.99"
RPUSH tasks "write tests" "deploy" "notify team"
LRANGE tasks 0 -1
HSET product:99 name "Widget" price "9.99" stock "100"
HGET product:99 name
HGET product:99 price
What is the time complexity of LPUSH and RPUSH on a Redis List?
Which command retrieves all fields and values from a Redis Hash?
You need to store a user record with fields like name, email, and age under one key. Which Redis type fits best?
Which data structure would you choose to implement a FIFO message queue in Redis?