Home / News / Redis Basics – Getting Started and Core Data Structures

Redis Basics – Getting Started and Core Data Structures

Redis: The Ultimate In-Memory Data Store

Redis, the ultimate in-memory data store, has been a game-changer for developers looking to build powerful applications and services. In this beginner-friendly guide, we’ll cover how to setup Redis locally or with Docker, work with core data structures (strings, hashes, lists, sets, sorted sets), and leverage its various features for real-time apps, queues, leaderboards, and more.

1. Start Redis Locally or with Docker

To start Redis locally or with Docker, follow these steps:

  • Install Redis on your local machine or docker host:
  • Set up the Redis server using the `redis-server` command:
  • Run the Redis Docker container:
  • Connect to the Redis container using the Redis CLI:
  • Test the connection using the `PING` command:
  • Install the Redis Docker image:
  • Start the Redis container using the `docker run` command:
  • Open the Redis Docker CLI:
  • Redis is more than just a cache—it’s a powerful in-memory data store that supports real-time apps, queues, leaderboards, and more.

    In this beginner-friendly guide, we’ll cover how to:
    ✅ Set up Redis locally or with Docker
    ✅ Use Redis CLI for quick testing
    ✅ Work with core data structures (Strings, Hashes, Lists, Sets, Sorted Sets)

    🚀 Setup & Basics
    Start Redis

    Start Redis (local)

    redis-server

    Run with Docker
    docker run --name redis -p 6379:6379 -d redis

    Open Redis CLI
    redis-cli

    Test Connection

    PING
    # PONG
    

    📦 Core Data Structures
    🔹 Strings

    SET name "Asad"
    GET name
    INCR counter
    

    Use cases: counters, sessions, caching simple values.

    Diagram:

    key    →   value
    ----------------
    name   →   "Asad"
    counter →   1
    

    🔹 Hashes

    HSET user:1 name "Asad" age "25"
    HGETALL user:1
    

    Use cases: store JSON-like objects (e.g., user profiles).

    Diagram:

    user:1
     ├── name → "Asad"
     └── age  → "25"
    

    🔹 Lists

    LPUSH tasks "task1"
    RPUSH tasks "task2"
    LPOP tasks
    

    Use cases: queues (FIFO), stacks (LIFO).

    Diagram (FIFO Queue):

    [ task1 ] → [ task2 ] → [ task3 ]

    🔹 Sets
    SADD tags “redis” “database” “cache”
    SMEMBERS tags

    Use cases: unique collections (tags, categories, followers).

    Diagram:

    tags = { “redis”, “database”, “cache” }

    🔹 Sorted Sets
    ZADD scores 100 “Asad” 200 “Plabon”
    ZRANGE scores 0 -1 WITHSCORES

    Use cases: leaderboards, rankings, priority queues.

    Diagram:

    +——+———+
    |User | Score |
    +——+———+
    |Asad | 100 |
    |Plabon| 200 |

    ✅ Wrap-Up

    That’s the foundation of Redis. With just a few commands, you can build counters, queues, and ranking systems.

    👉 In the next article, we’ll go deeper into advanced Redis concepts like Pub/Sub, Streams, persistence, clustering, and real-world AI use cases.

Tagged: