Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

React Cache Redis Laravel Package

wyrihaximus/react-cache-redis

Redis-backed cache adapter for ReactPHP implementing the react/cache interface. Built on clue/reactphp-redis, supports key prefixing, and integrates with async React event loops for fast, non-blocking caching in your applications.

View on GitHub
Deep Wiki
Context7

Getting Started

This package is not for Laravel—it’s for ReactPHP applications requiring non-blocking Redis caching. Laravel’s synchronous cache system (Illuminate\Contracts\Cache) is fundamentally incompatible with react/cache. If you’re using Laravel, this package serves no purpose; use Laravel’s built-in redis cache driver instead.

To get started only if building an event-driven app with ReactPHP:

  1. Install via Composer: composer require wyrihaximus/react-cache-redis clue/redis-react
  2. Create a lazy Redis client using Clue’s factory:
    $client = (new \Clue\React\Redis\Factory())->createLazyClient();
    
  3. Instantiate the cache:
    $cache = new \WyriHaximus\React\Cache\Redis($client, 'myapp:cache:v1:');
    
  4. Use like any react/cache implementation (e.g., Promise $cache->get('key'), Promise $cache->set('key', $value, $ttl)).

Implementation Patterns

  • Never block the event loop: All cache operations return Promises—always use await (with React\Promise\resolve() or async functions) or chain with then().
  • Prefixed keys for safety: Always use a namespaced prefix ('service:env:version:') to prevent key collisions across microservices or environments.
  • Lazy client is key: Use createLazyClient()—it defers connection until the first operation, avoiding startup blocking and handling reconnection automatically.
  • Pool with reactor: Integrate into your ReactPHP server (e.g., react/http) by injecting the cache instance into request handlers:
    $server->on('request', function ($req, $res) use ($cache) {
        $cache->get('user:' . $id)->then(function ($data) use ($res) {
            // non-blocking cache hit
            $res->writeHead(200);
            $res->end($data);
        });
    });
    
  • Typed keys & TTL: Leverage PHP 8+ typing and default TTLs—this package respects react/cache's int|float|null $ttl signature.

Gotchas and Tips

  • 0 dependents, low stars: This is a niche, specialized package. Use only if you’re committed to ReactPHP’s async ecosystem—not for Laravel, Symfony, or traditional frameworks.
  • Redis connection pitfalls: Lazy clients don’t fail at instantiation—errors surface during first operation. Wrap all cache calls in try/catch within the promise chain to handle connection failures gracefully.
  • TTL rounding: Redis SETEX uses integer seconds; float TTLs are cast silently. Validate TTLs for sub-second precision needs (e.g., max(1, (int)$ttl)).
  • Prefix ≠ namespace: The prefix is a raw string prepended to all keys—ensure it ends with : to avoid truncated keys (e.g., 'prefix' + 'key''prefixkey' is broken; 'prefix:' is safe).
  • Future releases: Check release dates—2025-04-27 is likely a packaging artifact, but verify composer.json's require.php matches your runtime (currently PHP 8.3+).
  • Extension points: Implement custom serializers via $cache->withSerializer() if caching complex objects or needing compression (e.g., with igbinary or zlib).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4