0Pricing
Redis Caching & Messaging (Pub/Sub, Streams) · Lesson

Core Redis Data Structures

Understand and apply Strings, Hashes, Lists, Sets, and Sorted Sets for various data modeling needs.

Core Redis Data Structures is a free Redis Caching & Messaging (Pub/Sub, Streams) lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Redis Caching & Messaging (Pub/Sub, Streams) learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Redis Data Types & Strings

Redis offers real data structures, not just plain keys. We start with Strings: a value up to 512 MB holding text, JSON, or binary — like a persistent variable.

Strings: Set & Get

Store and read a String with SET and GET. The code below sets a couple of keys and fetches them back.

SET mykey "Hello CoddyKit!"
GET mykey
SET user:1:name "Alice"
GET user:1:name

Hashes: Store Objects

Redis Hashes are like objects: many field-value pairs under one key. Perfect for modeling things like a user profile with several attributes.

Hashes: HSET & HGETALL

Use HSET to set fields in a hash, HGETALL to read them all, and HGET for a single field. The code below builds and reads a user hash.

HSET user:1 name "Alice" email "alice@example.com" age 30
HGETALL user:1
HGET user:1 name

Lists: Ordered Collections

Redis Lists are ordered string collections — push or pop from either end. Great for queues, stacks, and recent-activity feeds that keep insertion order.

Lists: LPUSH & LRANGE

LPUSH adds to the head, RPUSH to the tail, and LRANGE reads a range (0 -1 means everything). The code below pushes and lists items.

LPUSH mylist "task A" "task B"
RPUSH mylist "task C"
LRANGE mylist 0 -1
LPOP mylist
LRANGE mylist 0 -1

Sets: Unique Items

Redis Sets are unordered collections of unique strings — duplicates are silently ignored. Ideal for unique visitors, tags, or friendships.

Sets: SADD & SMEMBERS

SADD adds members (dupes ignored), SMEMBERS lists them all, and SISMEMBER checks membership. The code below demonstrates all three.

SADD unique_users "user:101" "user:102" "user:101"
SMEMBERS unique_users
SISMEMBER unique_users "user:102"

Sorted Sets: Ranked Data

Redis Sorted Sets pair each unique member with a score and keep them ordered by it — perfect for leaderboards, rankings, and priority queues.

Sorted Sets: ZADD & ZRANGE

ZADD adds scored members, ZRANGE reads a range (add WITHSCORES to see scores), and ZSCORE gets one member's score. See the code below.

ZADD leaderboard 100 "PlayerA" 150 "PlayerB" 75 "PlayerC"
ZRANGE leaderboard 0 -1 WITHSCORES
ZSCORE leaderboard "PlayerB"

Data Structure Challenge

Imagine you need to store a list of unique product tags for an item, and you don't care about their order. Which Redis data structure is best suited for this?

Recap: Structures Mastered

Recap: Redis data structures — Strings for basics, Hashes for objects, Lists for ordered queues, Sets for unique items, Sorted Sets for ranked data.

Frequently asked questions

Is the “Core Redis Data Structures” lesson free?

Yes — the full text of “Core Redis Data Structures” is free to read here on the web, and the Redis Caching & Messaging (Pub/Sub, Streams) course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Redis Caching & Messaging (Pub/Sub, Streams) course, upgrade to CoddyKit PRO.

What will I learn in “Core Redis Data Structures”?

Understand and apply Strings, Hashes, Lists, Sets, and Sorted Sets for various data modeling needs. You practise Redis Caching & Messaging (Pub/Sub, Streams) with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Redis Caching & Messaging (Pub/Sub, Streams)?

No prior experience is required. Redis Caching & Messaging (Pub/Sub, Streams) on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Core Redis Data Structures” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Redis Caching & Messaging (Pub/Sub, Streams) lesson?

Yes. Every Redis Caching & Messaging (Pub/Sub, Streams) lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Introduction to Redis
  2. Redis CLI Basics
  3. Core Redis Data Structures
  4. Key Expiration and TTL in Redis
← Back to Redis Caching & Messaging (Pub/Sub, Streams)