Podstawowe struktury danych Redis
Poznają Państwo zastosowania typów Strings, Hashes, Lists, Sets i Sorted Sets w różnych modelach danych.
Podstawowe struktury danych Redis to bezpłatna lekcja Redis Caching & Messaging (Pub/Sub, Streams) na CoddyKit. To lekcja 3 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Redis Caching & Messaging (Pub/Sub, Streams), a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Redis Caching & Messaging (Pub/Sub, Streams) zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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:nameHashes: 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 nameLists: 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 -1Sets: 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.
Często zadawane pytania
Czy lekcja „Podstawowe struktury danych Redis” jest bezpłatna?
Tak — pełny tekst „Podstawowe struktury danych Redis” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Redis Caching & Messaging (Pub/Sub, Streams), przejdź na CoddyKit PRO. Kurs Redis Caching & Messaging (Pub/Sub, Streams) zawiera 4 lekcji w sumie.
Co nauczysz się w „Podstawowe struktury danych Redis”?
Poznają Państwo zastosowania typów Strings, Hashes, Lists, Sets i Sorted Sets w różnych modelach danych. Ćwiczysz Redis Caching & Messaging (Pub/Sub, Streams) z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Redis Caching & Messaging (Pub/Sub, Streams)?
Nie wymagamy żadnego doświadczenia. Redis Caching & Messaging (Pub/Sub, Streams) w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 3 z 4.
Ile czasu zajmuje lekcja „Podstawowe struktury danych Redis”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Redis Caching & Messaging (Pub/Sub, Streams)?
Tak. Każda lekcja Redis Caching & Messaging (Pub/Sub, Streams) zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Wprowadzenie do Redis
- Podstawy Redis CLI
- Podstawowe struktury danych Redis
- Wygasanie kluczy i TTL w Redis