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

간단한 메시지 브로드캐스트

Redis CLI와 클라이언트 라이브러리를 사용해 채널에 메시지를 게시하고 수신을 위해 구독하는 연습을 합니다.

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

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

What is Broadcasting?

In the world of Pub/Sub, broadcasting means sending a single message that can be received by many listeners at once.

Think of it like a radio station: the station broadcasts music, and anyone tuned to that frequency can hear it.

  • One sender (publisher)
  • Many receivers (subscribers)
  • Decoupled communication

The Publisher's Role

A publisher is the entity that sends messages. It doesn't care who is listening or if anyone is listening at all.

Publishers simply send messages to a specific channel. Redis then takes care of delivering that message to all active subscribers of that channel.

CLI: Publishing Messages

You can easily publish messages using the Redis Command-Line Interface (CLI). The command is straightforward:

PUBLISH channel_name "Your message content"

Let's say you want to send a news update to a channel called newsfeed:

PUBLISH newsfeed "Breaking: Redis is awesome!"

The Subscriber's Role

A subscriber is the entity that listens for messages. It 'tunes in' to one or more specific channels.

When a message is published to a channel a subscriber is listening to, Redis delivers that message to the subscriber.

CLI: Subscribing to Channels

To start listening for messages on a channel via the Redis CLI, you use the SUBSCRIBE command:

SUBSCRIBE channel_name

Once you execute this command, your CLI will enter a listening mode, waiting for messages.

SUBSCRIBE newsfeed

Demo: CLI Publish & Subscribe

To see Pub/Sub in action with the CLI, you need two separate terminal windows:

  1. Window 1 (Subscriber): Run redis-cli SUBSCRIBE chatroom
  2. Window 2 (Publisher): Run redis-cli PUBLISH chatroom "Hello everyone!"

You'll see the message appear instantly in Window 1!

# Window 1 (Subscriber)
redis-cli SUBSCRIBE chatroom

# Window 2 (Publisher)
redis-cli PUBLISH chatroom "Hello everyone!"

Beyond CLI: Client Libraries

While the CLI is great for testing, real applications use client libraries. These libraries provide APIs in your preferred programming language (like Python, Java, Node.js) to interact with Redis.

Using client libraries makes it easy to integrate Redis Pub/Sub into your application logic.

Python Client: Publishing

Here's how to publish a message using the popular redis-py client library in Python. This script will connect to Redis and send a message to a channel.

import redis

r = redis.Redis(decode_responses=True)

channel_name = "app_updates"
message_content = "New feature released! Check it out."

r.publish(channel_name, message_content)
print(f"Published '{message_content}' to '{channel_name}'")

Python Client: Subscribing

This Python script demonstrates how to subscribe to a channel and receive a single message. It then exits, making it suitable for a quick runnable example.

In a real application, the for message in pubsub.listen(): loop would typically run continuously.

import redis

r = redis.Redis(decode_responses=True)
pubsub = r.pubsub()

channel_name = "app_updates"
pubsub.subscribe(channel_name)

print(f"Listening on '{channel_name}' for one message...")
for message in pubsub.listen():
    if message['type'] == 'message':
        print(f"Received: {message['data']}")
        break # Exit after first message
print("Subscriber finished.")

Quick Check: Pub/Sub Actions

You've learned about the fundamental commands for Redis Pub/Sub. Let's see if you can identify the correct action.

Recap: Broadcasting Messages

In this lesson, we explored how to broadcast messages using Redis Pub/Sub:

  • Publishers send messages to channels without knowing the subscribers.
  • Subscribers listen to specific channels to receive messages.
  • We used the Redis CLI with PUBLISH and SUBSCRIBE.
  • We also saw how to implement simple publishers and subscribers using Python client libraries.

Next, we'll dive deeper into building more complex real-time applications!

자주 묻는 질문

“간단한 메시지 브로드캐스트” 강의는 무료인가요?

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

“간단한 메시지 브로드캐스트”에서 뭘 배우나요?

Redis CLI와 클라이언트 라이브러리를 사용해 채널에 메시지를 게시하고 수신을 위해 구독하는 연습을 합니다. 브라우저에서 직접 실행하는 실습 코드로 Redis Caching & Messaging (Pub/Sub, Streams)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

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

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

“간단한 메시지 브로드캐스트” 강의는 얼마나 걸리나요?

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

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

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

이 강의의 모든 강의

  1. Pub/Sub 소개
  2. Redis Pub/Sub 작동 원리
  3. 간단한 메시지 브로드캐스트
  4. 채널과 키스페이스 알림 비교
← Redis Caching & Messaging (Pub/Sub, Streams)(으)로 돌아가기