f in x
Redis from Scratch: Installation, Data Types, and Essential Commands
> cd .. / HUB_EDITORIALE
Analisi dei dati e metriche

Redis from Scratch: Installation, Data Types, and Essential Commands

[2026-06-02] Author: Ing. Calogero Bono

Your web app is hitting the database on every request, APIs respond in 500ms, and the server is struggling. You need a fast, in-memory data store. Redis is the answer. But installing and using it isn't magic — it's a concrete process. At Meteora Web, we put Redis into production for clients of all sizes. Let's start from scratch: installation, data types, and core commands. No fluff, just action.

Installing Redis: Choose Your Path

Redis runs on Linux, macOS, and Windows (via WSL). We always recommend a Linux server for production — stable, performant, no surprises. Here's how to install it in the three most common scenarios.

Linux (Ubuntu/Debian)

sudo apt update
sudo apt install redis-server
# Start and enable on boot
sudo systemctl enable redis-server
sudo systemctl start redis-server
# Verify
redis-cli ping
# Should output: PONG

macOS (Homebrew)

brew install redis
brew services start redis
redis-cli ping

Windows (WSL or Docker)

On Windows, use WSL with Ubuntu or Docker:

docker run --name redis -p 6379:6379 -d redis

Once installed, connect with redis-cli. It's your command-line playground for Redis.

Redis Data Types: Beyond Simple Strings

Redis is not a plain key-value store. It offers advanced data structures that solve real problems without complex code. Each type has a specific use case. Let's learn them with hands-on examples.

String — the building block

A string holds a simple value: a token, a session, a cached HTML page. Commands: SET, GET, SETEX (with expiry).

SET user:1:name "Mario Rossi"
GET user:1:name
# With TTL (expiry in seconds):
SETEX session:abc123 3600 "session_data"

List — queues and buffers

A list is a FIFO or LIFO queue. Perfect for job queues or temporary logs.

LPUSH tasks "email_notification"
LPUSH tasks "generate_pdf"
RPOP tasks  # extracts the first ("email_notification")

Set — duplicate-free collections

Useful for tags, unique users, permissions.

SADD article:42:tags "redis" "database" "caching"
SMEMBERS article:42:tags

Sorted Set — rankings and priority queues

Each element has a score. Ideal for leaderboards, rankings, priority queues.

ZADD leaderboard 100 "user1" 200 "user2" 50 "user3"
ZRANGE leaderboard 0 -1 WITHSCORES  # ascending
ZREVRANGE leaderboard 0 2 WITHSCORES  # top 3

Hash — structured objects

A hash maps fields to values. Perfect for representing a record: user profile, metadata, configuration.

HSET user:42 name "Maria" email "maria@example.com" age 28
HGET user:42 name
HGETALL user:42

Essential Commands for Daily Use

Beyond type-specific commands, there are cross-cutting operations you'll use in every project.

Existence and deletion

EXISTS user:1:name    # 1 = exists, 0 = no
DEL user:1:name       # deletes the key
FLUSHALL              # deletes EVERYTHING (careful!)

Time-to-Live (TTL) — your caching best friend

EXPIRE cache:homepage 3600   # expires in 1 hour
TTL cache:homepage           # seconds remaining

Setting TTL is the difference between a cache that works and one that fills your RAM with stale data. We always do it.

Atomic counters

INCR page:visits           # increment by 1
INCRBY page:visits 5       # increment by 5
DECR page:visits           # decrement

Guaranteed atomicity. No race conditions.

First Practical Steps

Now that you know the commands, see how to use them in a real flow. Suppose you want to cache the result of an expensive query.

# Simulate an expensive computed value
SETEX expensive:result 60 "{\"data\": \"computed value\"}"
# Next time, before recalculating, check
GET expensive:result

In our Laravel applications we use Redis for sessions, route cache, and queues. Setup is immediate: just configure the driver in the .env file.

Common Mistakes to Avoid Right Now

  • Using KEYS * in production: blocks Redis for seconds on large datasets. Use SCAN instead.
  • Forgetting TTL: data stays in memory forever. Always set an expiry for temporary data.
  • Keys that are too large: a 10 MB string slows everything down. Split or compress.
  • Ignoring persistence: if the server restarts, you lose everything. Evaluate RDB or AOF based on your requirements.

In Summary — What To Do Now

  1. Install Redis on your development environment (Linux, macOS, Docker).
  2. Connect with redis-cli and try each data type using the commands from this guide.
  3. Set a TTL on a key and verify it expires.
  4. Read the official documentation — it's clear and well-structured: redis.io/docs.
  5. Integrate Redis into your application: if you use PHP, try Predis; if Node.js, try ioredis. But first, master the console.

Redis is a powerful tool, but you need to understand it. We use it every day to speed up sites, manage queues, and reduce database load. Start here and you'll see the difference in your response times.

Sponsored Protocol

Ing. Calogero Bono

> AUTHOR_EXTRACTED

Ing. Calogero Bono

Co-founder di Meteora Web. Ingegnere informatico, sviluppo ecosistemi digitali ad alte prestazioni. AI, automazione, SEO tecnica e infrastrutture web. Scrivo di tecnologia per rendere complesso… semplice.

[ Read Full Dossier ]

Hai bisogno di applicare questa strategia?

Esegui il protocollo di contatto per iniziare un progetto con noi.

> INIZIA_PROGETTO

Sponsored

> MW_JOURNAL

> READ_ALL()