← スキル䞀芧に戻る
eco2-team

redis-patterns

by eco2-team

🌱 읎윔에윔(Eco²) BE

⭐ 0🍎 0📅 2026幎1月25日
GitHubで芋るManusで実行

SKILL.md


name: redis-patterns description: Redis 팹턮 가읎드. Cache-Aside, Rate Limiting, Pub/Sub, Streams 구현 시 ì°žì¡°. "redis", "cache", "rate limit", "pubsub", "streams" 킀워드로 튞늬거.

Redis Patterns Guide

Eco² Redis 사용 팹턮

┌─────────────────────────────────────────────────────────────────────────┐
│                    Redis Usage in Eco²                                   │
├──────────────────────────────────────────────────────────────────────────
│                                                                          │
│  Cache-Aside (L1)                                                        │
│  ├─ LangGraph Checkpoint 캐시                                           │
│  ├─ Intent Classification 캐시                                          │
│  └─ Session State 캐시                                                  │
│                                                                          │
│  Rate Limiting                                                           │
│  └─ API 요청 제한 (Sliding Window)                                      │
│                                                                          │
│  Pub/Sub                                                                 │
│  └─ SSE 싀시간 읎벀튞 (sse:events:{job_id})                             │
│                                                                          │
│  Streams                                                                 │
│  ├─ 읎벀튞 버퍌 ({domain}:events:{shard})                               │
│  └─ State KV ({domain}:state:{job_id})                                  │
│                                                                          │
│  Human-in-the-Loop                                                       │
│  ├─ 입력 요청 (input:request:{job_id})                                  │
│  └─ 상혞작용 상태 (interaction:state:{job_id})                          │
│                                                                          │
└─────────────────────────────────────────────────────────────────────────┘

죌요 팹턮

1. Cache-Aside

async def get_with_cache(
    key: str,
    fetch_fn: Callable[[], Awaitable[T]],
    ttl: int = 3600,
) -> T:
    """Cache-Aside 팹턮"""
    # 1. 캐시 조회
    cached = await redis.get(key)
    if cached:
        return deserialize(cached)

    # 2. 원볞 조회
    data = await fetch_fn()

    # 3. 캐시 저장
    await redis.setex(key, ttl, serialize(data))

    return data

2. Rate Limiting (Sliding Window)

async def check_rate_limit(
    key: str,
    limit: int,
    window_seconds: int,
) -> bool:
    """Sliding Window Rate Limit"""
    now = time.time()
    window_start = now - window_seconds

    pipe = redis.pipeline()
    pipe.zremrangebyscore(key, 0, window_start)  # 였래된 Ʞ록 제거
    pipe.zadd(key, {str(now): now})               # 현재 요청 추가
    pipe.zcard(key)                               # 요청 수 확읞
    pipe.expire(key, window_seconds)

    _, _, count, _ = await pipe.execute()
    return count <= limit

3. Pub/Sub

async def publish_event(job_id: str, event: dict) -> None:
    """읎벀튞 발행"""
    channel = f"sse:events:{job_id}"
    await redis.publish(channel, json.dumps(event))

async def subscribe_events(job_id: str) -> AsyncIterator[dict]:
    """읎벀튞 구독"""
    pubsub = redis.pubsub()
    await pubsub.subscribe(f"sse:events:{job_id}")

    async for message in pubsub.listen():
        if message["type"] == "message":
            yield json.loads(message["data"])

4. Streams (Consumer Group)

async def consume_stream(
    stream: str,
    group: str,
    consumer: str,
) -> AsyncIterator[tuple[str, dict]]:
    """Consumer Group êž°ë°˜ 슀튞늌 소비"""
    while True:
        messages = await redis.xreadgroup(
            groupname=group,
            consumername=consumer,
            streams={stream: ">"},
            block=5000,
            count=100,
        )

        for stream_name, events in messages:
            for event_id, data in events:
                yield event_id, data
                await redis.xack(stream_name, group, event_id)

Reference Files

Redis 읞슀턎슀 분늬

Eco² 큎러슀터 Redis 서비슀

읞슀턎슀K8s 서비슀용도
Streamsrfr-streams-redis.redis.svc.cluster.local:6379Streams, State KV (영속)
Pub/Subrfr-pubsub-redis.redis.svc.cluster.local:6379싀시간 전송 (휘발)
# ConfigMap 환겜변수 예시
CHAT_WORKER_REDIS_STREAMS_URL: redis://rfr-streams-redis.redis.svc.cluster.local:6379/0
CHAT_WORKER_REDIS_PUBSUB_URL: redis://rfr-pubsub-redis.redis.svc.cluster.local:6379/0

읞슀턎슀별 특성

rfr-streams-redis:    # Streams, State KV (영속)
  - AOF 활성화
  - Checkpoint 데읎터
  - Consumer Group

rfr-pubsub-redis:     # Pub/Sub (휘발)
  - 싀시간 전송 전용
  - SSE Gateway 구독

スコア

総合スコア

60/100

リポゞトリの品質指暙に基づく評䟡

✓SKILL.md

SKILL.mdファむルが含たれおいる

+20
✓LICENSE

ラむセンスが蚭定されおいる

+10
○説明文

100文字以䞊の説明がある

0/10
○人気

GitHub Stars 100以䞊

0/15
○最近の掻動

3ヶ月以内に曎新がある

0/10
○フォヌク

10回以䞊フォヌクされおいる

0/5
✓Issue管理

オヌプンIssueが50未満

+5
✓蚀語

プログラミング蚀語が蚭定されおいる

+5
○タグ

1぀以䞊のタグが蚭定されおいる

0/5

レビュヌ

💬

レビュヌ機胜は近日公開予定です