RateLimitMiddleware: pluggable storage (Redis/Memcached) - #487
Open
Ibochkarev wants to merge 3 commits into
Open
RateLimitMiddleware: pluggable storage (Redis/Memcached)#487Ibochkarev wants to merge 3 commits into
Ibochkarev wants to merge 3 commits into
Conversation
Extract file-based counters into RateLimitStoreInterface with optional Redis/Memcached backends via MODX settings or env, keeping file as default. Closes #349
Count the current request atomically before comparing to maxAttempts, and initialize Memcached counters with add() to avoid init races.
This was referenced Jul 29, 2026
RedisRateLimitStore now uses a single bucket key with a TTL window and an atomic Lua script (INCR + EXPIRE in one round-trip), removing the TOCTOU between the counter and a separate reset key. RateLimitStoreFactory routes shared-store fallbacks through a single fallbackToFile() helper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Описание
RateLimitMiddlewareбольше не пишет счётчики напрямую вsys_get_temp_dir(). Логика вынесена вRateLimitStoreInterface; по умолчанию используется file-драйвер (поведение single-node сохранено). Для multi-node можно включить Redis или Memcached через системные настройки или env — без обязательной composer-зависимости (нужны только PHP-расширения).Тип изменений
Связанные Issues
Closes #349
Как включить Redis (multi-node)
ext-redisна всех PHP-нодах.ms3_rate_limit_store=redisили envMS3_RATE_LIMIT_STORE=redis.ms3_rate_limit_redis_dsn=redis://:password@127.0.0.1:6379/0, илиMS3_RATE_LIMIT_REDIS_DSN, илиПри недоступном Redis/Memcached middleware автоматически откатывается на file store (warning в MODX log).
Как это было протестировано?
Конфигурация: PHP 8.4.17, branch
feat/issue-349-rate-limit-storeЧеклист