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

소비자 그룹 소개

소비자 그룹을 통해 여러 소비자가 스트림을 협력적이고 안정적으로 처리하는 방식을 이해합니다.

소비자 그룹 소개은(는) CoddyKit의 무료 Redis Caching & Messaging (Pub/Sub, Streams) 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Redis Caching & Messaging (Pub/Sub, Streams) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Redis Caching & Messaging (Pub/Sub, Streams) 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

What are Consumer Groups?

Redis Streams are powerful for logging and event sourcing. But what if multiple applications or instances need to process the same stream data, without duplicating work?

This is where Consumer Groups come in. They are a core feature of Redis Streams designed for reliable, shared message processing.

The Challenge: Multiple Readers

Imagine two services, Service A and Service B, both needing to process every new order from an orders_stream.

If both services simply use XREAD, they would both receive and process all messages, leading to duplicated effort or inconsistent states.

  • How do they know which messages are already processed?
  • How do they share the workload?

Solving Shared Stream Processing

Consumer Groups provide a way for multiple clients (consumers) to jointly read from the same Redis Stream.

They ensure that:

  • Each message is delivered to only one consumer within the group.
  • The state (which messages are pending, which are acknowledged) is managed by Redis.
  • Consumers can recover and resume processing from where they left off.

Key Concepts: Group, Consumer, PEL

Let's define the core parts of a Consumer Group:

  • Stream: The Redis Stream holding the messages.
  • Consumer Group: A logical group of consumers processing a stream.
  • Consumer: An individual client instance within a group.
  • Pending Entry List (PEL): A list maintained by Redis for each consumer, tracking messages that have been delivered but not yet acknowledged.

Setting Up Your First Group

Before consumers can join, a Consumer Group must be created on a specific stream. We use the XGROUP CREATE command.

The MKSTREAM option automatically creates the stream if it doesn't exist.

XGROUP CREATE my_stream my_group 0 MKSTREAM

Populating the Stream

Let's add a few messages to our my_stream so we have something to read. Remember, XADD is how you add entries to a stream.

XADD my_stream * sensor_id 1 temp 25.5
XADD my_stream * sensor_id 2 temp 24.9
XADD my_stream * sensor_id 1 temp 26.1

Consumers Joining the Group

Consumers read from a group using the XREADGROUP command. You specify the group name, the consumer name, and the stream ID to start reading from.

The special ID > means "read only new, unread messages that have not been delivered to any other consumer in this group yet."

XREADGROUP GROUP my_group consumer1 COUNT 1 STREAMS my_stream >

Confirming Message Processing (XACK)

After a consumer processes a message, it must acknowledge it using XACK. This tells Redis the message is handled and can be removed from the consumer's Pending Entry List (PEL).

This is crucial for reliability and prevents messages from being re-delivered if a consumer crashes.

XACK my_stream my_group 1678881234567-0

Why XACK Matters

Acknowledging messages is vital for two main reasons:

  • Reliability: If a consumer fails before acknowledging, the message remains in its PEL and can be claimed by another consumer later.
  • Resource Management: Unacknowledged messages stay in the PEL, consuming memory. Acknowledging keeps the PEL clean and efficient.

Consumer Group Basics

Which Redis command is used to create a new Consumer Group for a stream?

Recap: Consumer Groups

In this lesson, you learned about Redis Consumer Groups and how they enable multiple consumers to reliably process messages from a single stream, ensuring each message is handled only once.

You now understand the roles of groups, consumers, and the Pending Entry List (PEL), and how to use XGROUP CREATE, XREADGROUP, and XACK.

Next, we'll dive deeper into implementing consumer group logic and handling pending messages!

자주 묻는 질문

“소비자 그룹 소개” 강의는 무료인가요?

네 — “소비자 그룹 소개” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Redis Caching & Messaging (Pub/Sub, Streams) 강의 전체를 잠금 해제할 수 있습니다. Redis Caching & Messaging (Pub/Sub, Streams) 강의에는 총 4개의 강의가 포함되어 있습니다.

“소비자 그룹 소개”에서 뭘 배우나요?

소비자 그룹을 통해 여러 소비자가 스트림을 협력적이고 안정적으로 처리하는 방식을 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 Redis Caching & Messaging (Pub/Sub, Streams)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Redis Caching & Messaging (Pub/Sub, Streams)을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Redis Caching & Messaging (Pub/Sub, Streams)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“소비자 그룹 소개” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Redis Caching & Messaging (Pub/Sub, Streams) 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Redis Caching & Messaging (Pub/Sub, Streams) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 소비자 그룹 소개
  2. 소비자 그룹 로직 구현
  3. 대기 중인 메시지 및 장애 처리
  4. 소비자 그룹 지연 모니터링
← Redis Caching & Messaging (Pub/Sub, Streams)(으)로 돌아가기