Windows에서 Redis 설치 + Python Pub/Sub 샘플만 제공합니다.


1. Windows용 Redis 설치

설치 파일

  • Redis Windows용 MSI
    (Redis-x64-*.msi)

설치 옵션

  • ✅ Install as a Windows Service
  • ✅ Add to PATH

설치 확인 (PowerShell)

redis-cli ping

출력:

PONG

2. Python 환경 준비

pip install redis

3. Python Redis Pub/Sub 샘플

3-1. Subscriber (메시지 수신)

import redis

r = redis.Redis(host="127.0.0.1", port=6379, decode_responses=True)
pubsub = r.pubsub()
pubsub.subscribe("test:channel")

print("waiting...")
for msg in pubsub.listen():
    if msg["type"] == "message":
        print("받음:", msg["data"])

3-2. Publisher (메시지 전송)

import redis
import time

r = redis.Redis(host="127.0.0.1", port=6379, decode_responses=True)

while True:
    r.publish("test:channel", "hello from python")
    time.sleep(1)

4. 실행 순서

  1. Redis 서비스 실행
  2. subscriber.py 실행
  3. publisher.py 실행

5. 결과

waiting...
받음: hello from python
받음: hello from python
받음: hello from python
728x90

'Software > Python' 카테고리의 다른 글

Python 시작하기 - YOLO객체 감지  (1) 2024.09.09
Python 시작하기 - 수식편집기  (0) 2024.08.22
Python 시작하기 - 통계분석  (0) 2024.07.31
Python 시작하기 - AI 모델  (0) 2024.07.31
Python시작하기 - QRcode  (0) 2024.07.30

+ Recent posts