Search by

freyr / message-broker-ratelimit-redis

Freyr

Redis rate limit store for freyr/message-broker: the token buckets of the webhook lanes in Lua scripts, with a phpredis or a Predis client

Package info

github.com/freyr/message-broker-ratelimit-redis

pkg:composer/freyr/message-broker-ratelimit-redis

Statistics

Installs: 2

Dependents: 1

Suggesters: 1

Stars: 0

v0.1.0 2026-11-23 21:31 UTC

This package is auto-updated.

Last update: 2026-11-23 21:49:33 UTC


README

This package is the Redis rate limit store of the Freyr Message Broker library, namespace Freyr\MessageBroker\RateLimit\Redis\.

The repository freyr/message-broker-ratelimit-redis is a read-only copy of the folder ratelimit/redis/ of freyr/message-broker. Development, issues and pull requests are in freyr/message-broker. A release has the tag ratelimit-redis-v<version> in freyr/message-broker and the tag v<version> in freyr/message-broker-ratelimit-redis.

The adapter holds RedisRateLimiter, which implements the port Webhook\RateLimiter of the core in Redis. Each call is one atomic Lua script with the clock of the Redis primary. Each token bucket is one HASH with a time to live, and all keys of one deployment have one hash tag, so the store also works in Redis Cluster. The application gives the Redis client; the package opens no connection.

Requirements

  • PHP 8.4 or later
  • freyr/message-broker ^0.15 (the core)
  • Redis 7.0 or later, or Valkey 7.2 or later
  • One Redis client: ext-redis (a \Redis, \RedisCluster or Relay client) or predis/predis

Install

composer require freyr/message-broker-ratelimit-redis

Add a Redis client yourself: ext-redis or predis/predis.

Minimal wiring

use Freyr\MessageBroker\RateLimit\Redis\PhpRedisScriptRunner;
use Freyr\MessageBroker\RateLimit\Redis\RedisRateLimitConfig;
use Freyr\MessageBroker\RateLimit\Redis\RedisRateLimiter;

$redis = new \Redis();
$redis->connect('redis', 6379);

$rateLimiter = new RedisRateLimiter(new PhpRedisScriptRunner($redis), new RedisRateLimitConfig('shop.prod'));
// Give $rateLimiter to Webhook\DeliveryLoop of the core.

With Predis, use new PredisScriptRunner($client).

Documents

  • Redis rate limit store: the client bridges, the key prefix and the hash tag, the server versions, maxmemory-policy, the script cache, the tests
  • Webhooks: the rate limit rules of the core
  • Webhook delivery storage: the PostgreSQL store of the rate limit and the circuit breaker

Tests

The tests need Redis and no PostgreSQL; see Tests.