โ† Back to list
eco2-team

redis-patterns

by eco2-team

๐ŸŒฑ ์ด์ฝ”์—์ฝ”(Ecoยฒ) BE

โญ 0๐Ÿด 0๐Ÿ“… Jan 25, 2026

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 ๊ตฌ๋…

Score

Total Score

60/100

Based on repository quality metrics

โœ“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

Reviews

๐Ÿ’ฌ

Reviews coming soon