From 0f9480f0c2154ba0112f28e13754f03823d46317 Mon Sep 17 00:00:00 2001 From: Jacob Coffee Date: Sat, 10 Oct 2026 21:35:09 -0500 Subject: [PATCH 1/2] fix(examples): count same-timestamp requests in Redis rate limiter Sorted-set members were the bare timestamp, so requests landing on the same clock tick (common on Windows) overwrote each other and were undercounted. --- examples/full/redis_store.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/full/redis_store.py b/examples/full/redis_store.py index a8be3f6..7bae922 100644 --- a/examples/full/redis_store.py +++ b/examples/full/redis_store.py @@ -33,6 +33,7 @@ import os import time +import uuid from dataclasses import dataclass from typing import TYPE_CHECKING, Any @@ -251,8 +252,8 @@ async def increment(self, key: str, window: str) -> int: # Remove expired entries pipe.zremrangebyscore(redis_key, 0, window_start) # Add current request with timestamp as score - # Use timestamp + microseconds to ensure uniqueness - pipe.zadd(redis_key, {f"{now}": now}) + # Add a unique suffix so requests with the same timestamp aren't merged + pipe.zadd(redis_key, {f"{now}-{uuid.uuid4().hex}": now}) # Set TTL to auto-expire the key pipe.expire(redis_key, window_duration + 60) # Extra buffer # Get the count From 54995fe87ea725751be679f5d384b85d8b447f72 Mon Sep 17 00:00:00 2001 From: Jacob Coffee Date: Sat, 10 Oct 2026 21:37:50 -0500 Subject: [PATCH 2/2] ci: run CI when examples change Tests import examples/, so changes there need CI. --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ee73a7..9951ab1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,7 @@ on: paths: - 'src/**' - 'tests/**' + - 'examples/**' - 'pyproject.toml' - 'uv.lock' - '.github/workflows/ci.yml' @@ -14,6 +15,7 @@ on: paths: - 'src/**' - 'tests/**' + - 'examples/**' - 'pyproject.toml' - 'uv.lock' - '.github/workflows/ci.yml'