채널과 키스페이스 알림 비교
명시적인 Pub/Sub 채널과 Redis 키스페이스 알림의 차이와 각각을 사용해야 할 상황을 이해해 보세요.
채널과 키스페이스 알림 비교은(는) CoddyKit의 무료 Redis Caching & Messaging (Pub/Sub, Streams) 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Redis Caching & Messaging (Pub/Sub, Streams) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Redis Caching & Messaging (Pub/Sub, Streams) 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Two Ways to Get Notified
So far you have published to explicit channels with PUBLISH. Redis also offers keyspace notifications, which automatically emit events when keys change. Both deliver messages to subscribers, but the source differs.
Recap: Explicit Channels
With explicit channels, your application decides what to publish and when. The channel name is arbitrary text.
PUBLISH news.sports "Match ended 2-1"
SUBSCRIBE news.sportsWhat Are Keyspace Notifications?
Keyspace notifications let Redis itself publish an event whenever a key is modified, expired, or evicted. You subscribe to special channels to observe data changes without your app having to publish anything.
Enabling Notifications
They are off by default. Enable them with the notify-keyspace-events config flag, where letters select event classes.
Kkeyspace eventsEkeyevent eventsAall command/event typesxexpired,ggeneric,$string
CONFIG SET notify-keyspace-events KEAKeyspace vs Keyevent
There are two channel families:
- Keyspace:
__keyspace@0__:mykeytells you which event happened to a key - Keyevent:
__keyevent@0__:deltells you which keys had a given event
The @0 is the database number.
PSUBSCRIBE __keyspace@0__:*
PSUBSCRIBE __keyevent@0__:expiredSubscribing to Expirations
A common use case is reacting when a key expires, for example to clean up a session. Enable Ex and subscribe to the expired keyevent channel.
CONFIG SET notify-keyspace-events Ex
SUBSCRIBE __keyevent@0__:expiredA Practical Flow
Set a session key with a TTL. When it expires, Redis publishes to the expired channel, and your worker reacts.
SET session:abc "data" EX 30
# 30s later, subscriber receives:
# __keyevent@0__:expired -> session:abcDelivery Caveats
Keyspace notifications use Pub/Sub, so they are fire-and-forget. If no client is subscribed when the event fires, the message is lost. They are also not guaranteed for keys that expire while idle until a read or the background expiry cycle touches them.
When to Use Each
Use explicit channels when your app controls the event semantics (chat, notifications, custom events). Use keyspace notifications when you want to react to data mutations you do not directly control, like cache invalidation or expiry cleanup.
Performance Note
Enabling A (all events) on a busy server generates a high volume of messages and adds overhead. Subscribe only to the specific event classes you need.
CONFIG SET notify-keyspace-events EgxSummary So Far
Explicit channels are app-driven; keyspace notifications are Redis-driven. Both ride on the same lightweight Pub/Sub transport, so neither persists messages.
Quick Check
Pick the correct statement about keyspace notifications.
Recap
You compared explicit Pub/Sub channels with keyspace notifications, learned how to enable notifications via notify-keyspace-events, the keyspace vs keyevent channel families, and the fire-and-forget delivery caveats. Reach for keyspace notifications to react to data changes without publishing them yourself.
자주 묻는 질문
“채널과 키스페이스 알림 비교” 강의는 무료인가요?
네 — “채널과 키스페이스 알림 비교” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Redis Caching & Messaging (Pub/Sub, Streams) 강의 전체를 잠금 해제할 수 있습니다. Redis Caching & Messaging (Pub/Sub, Streams) 강의에는 총 4개의 강의가 포함되어 있습니다.
“채널과 키스페이스 알림 비교”에서 뭘 배우나요?
명시적인 Pub/Sub 채널과 Redis 키스페이스 알림의 차이와 각각을 사용해야 할 상황을 이해해 보세요. 브라우저에서 직접 실행하는 실습 코드로 Redis Caching & Messaging (Pub/Sub, Streams)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Redis Caching & Messaging (Pub/Sub, Streams)을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Redis Caching & Messaging (Pub/Sub, Streams)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“채널과 키스페이스 알림 비교” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Redis Caching & Messaging (Pub/Sub, Streams) 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Redis Caching & Messaging (Pub/Sub, Streams) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- Pub/Sub 소개
- Redis Pub/Sub 작동 원리
- 간단한 메시지 브로드캐스트
- 채널과 키스페이스 알림 비교