Software/Python

Python 시작하기 - Windows에서 Redis 설치

초짜호야 2026. 2. 21. 15:50
728x90

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