Thuta Learning
Redis
BasicData & Databasesbeginner

Lists and Sets

What you'll walk away with

  • Explain the core ideas behind Lists and Sets
  • Run the sample Redis command or code and verify its output
  • Apply the technique correctly to the Tutorial Platform and production scenarios

Build the mental model

Lists preserve insertion order and support push/pop at both ends, making them useful for queues, stacks, and bounded recent history. Sets store unordered unique members and support membership, intersection, union, and difference. When jobs need acknowledgments and recovery, prefer Streams over a simple list pop.

Connect it to a real scenario

Store user 42's recent tutorial IDs in a list and cap it at 20 with `LTRIM`. Store tutorial tags and user interests in sets, then use `SINTER` to find recommendation overlap.

Try the working example

shell
LPUSH recent:user:42 tutorial:7 tutorial:9 tutorial:12
LTRIM recent:user:42 0 19
LRANGE recent:user:42 0 -1

SADD interests:user:42 database backend redis
SADD tags:tutorial:12 redis database caching
SISMEMBER tags:tutorial:12 redis
SINTER interests:user:42 tags:tutorial:12
You should see
You create a bounded recent list and calculate unique interest overlap.

5-minute try-it

Cap a recently viewed list at five, observe duplicate behavior, and run union/difference on two sets.

One important caution

Lists do not enforce uniqueness. Use a set or a coordinated list-plus-set design when uniqueness matters.

Redis — Data TypesRedis

Easy traps

  • Lists do not enforce uniqueness. Use a set or a coordinated list-plus-set design when uniqueness matters.
  • Validate sample commands on a local or test instance with recoverable data before applying them to production Redis.

Exercise

Cap a recently viewed list at five, observe duplicate behavior, and run union/difference on two sets.

You'll know it worked when: You create a bounded recent list and calculate unique interest overlap.

Lists and Sets | Thuta Learning