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

Redis React Laravel Package

clue/redis-react

Async Redis client for ReactPHP. Send commands in parallel with automatic pipelining and promise-based responses. Event-driven Pub/Sub support, lightweight SOLID design, and strong test coverage for Redis v2.6+.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer (composer require clue/redis-react) and importing the React\Redis\Client class. Initialize the client using Client::create('tcp://127.0.0.1:6379'), passing in a Redis server URI. Your first use case will likely be a simple non-blocking get or set operation within a ReactPHP application — e.g., fetching a cached value without halting the event loop. Check examples/ in the repo for minimal working demos.

Implementation Patterns

  • Single-client pattern: Use a singleton Client instance shared across your app for low-overhead, stateful connections. Reuse the connection rather than creating new ones per request.
  • Pub/Sub handling: Leverage $client->subscribe() and attach callbacks to incoming messages — ideal for real-time features like chat or notifications in long-running processes.
  • Pipeline usage: Batch commands via $client->pipeline() for bulk operations (e.g., populating caches), reducing network round-trips while preserving non-blocking behavior.
  • Connection pooling (via Pool or manual): For higher throughput, manually manage multiple clients in a pool or combine with clue/reactphp-mysql-style patterns to avoid bottlenecks.
  • Promise chaining/composition: Integrate with React\Promise (e.g., all(), resolve()) to coordinate Redis I/O with other async operations (HTTP requests, timers, etc.).

Gotchas and Tips

  • Event loop dependency: Always ensure commands run within the active ReactPHP event loop; calling run() on the loop after issuing commands is critical — forgetting this causes silent failures.
  • Connection lifetime management: Connections auto-reconnect by default but may drop during long idle periods. Consider issuing periodic PING or using on('close', ...) to re-initialize state.
  • Error handling: Errors are emitted via the 'error' event and returned as rejected promises — always attach both .then(null, $handler) and on('error', ...) for full coverage.
  • Serialization: The client only handles raw strings/binary. Use json_encode/json_decode manually (or with helpers like clue/reactphp-redis-json) to avoid accidentally storing JSON strings without understanding size/cost.
  • Testing gotchas: Unit tests can’t rely on live Redis. Mock ClientInterface, or use React\Promise\Promise mocks — better yet, test pub/sub/pipeline behavior with a local Redis instance in CI and integration suites.
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
milesj/emojibase
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