Redis Caching & Messaging (Pub/Sub, Streams) · Lezione

Strutture dati fondamentali di Redis

Comprenda e utilizzi Stringhe, Hash, Liste, Set e Set ordinati per diverse esigenze di modellazione dei dati.

Lezione 3 di 412 passaggi

Strutture dati fondamentali di Redis è una lezione Redis Caching & Messaging (Pub/Sub, Streams) gratuita su CoddyKit. Questa è la lezione 3 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Redis Caching & Messaging (Pub/Sub, Streams), e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Redis Caching & Messaging (Pub/Sub, Streams) include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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.

Gratis per iniziare

Impara Redis Caching & Messaging (Pub/Sub, Streams) con un tutor IA — gratis

Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.

Corsi
12
Lezioni
48

Domande Frequenti

La lezione «Strutture dati fondamentali di Redis» è gratuita?

Sì — il testo completo di «Strutture dati fondamentali di Redis» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Redis Caching & Messaging (Pub/Sub, Streams), passa a CoddyKit PRO. Il corso Redis Caching & Messaging (Pub/Sub, Streams) include 4 lezioni in totale.

Cosa imparerò in «Strutture dati fondamentali di Redis»?

Comprenda e utilizzi Stringhe, Hash, Liste, Set e Set ordinati per diverse esigenze di modellazione dei dati. Eserciti Redis Caching & Messaging (Pub/Sub, Streams) con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Redis Caching & Messaging (Pub/Sub, Streams)?

Non è richiesta alcuna esperienza precedente. Redis Caching & Messaging (Pub/Sub, Streams) su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 3 di 4.

Quanto tempo richiede la lezione «Strutture dati fondamentali di Redis»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Redis Caching & Messaging (Pub/Sub, Streams)?

Sì. Ogni lezione Redis Caching & Messaging (Pub/Sub, Streams) include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Introduzione a Redis
  2. Nozioni di base sulla Redis CLI
  3. Strutture dati fondamentali di Redis
  4. Scadenza delle chiavi e TTL in Redis
← Torna a Redis Caching & Messaging (Pub/Sub, Streams)