- Is hyperf/redis compatible with Laravel?
- No. hyperf/redis is built specifically for the Hyperf framework and its coroutine runtime, not for Laravel's HTTP/queue lifecycle. Laravel applications should use Laravel's Redis integration with predis or phpredis instead. The configuration and dependency-injection style may feel familiar, but the package is not a drop-in Laravel component.
- How do I install hyperf/redis in a Hyperf application?
- Install it with Composer using composer require hyperf/redis, then make sure your Hyperf application's config provider setup is active. Add Redis connection details under Hyperf's config/autoload directory, typically redis.php, and use environment variables for host, port, password, and database. After that you can inject the Redis factory or named connections through Hyperf's DI container.
- How do I configure Redis connections and connection pooling in Hyperf?
- Configure Redis under Hyperf's autoload configuration, usually config/autoload/redis.php, where you can define multiple named connections and pool settings. Pool options let you control minimum and maximum connections, timeouts, and related behavior for coroutine-safe reuse. Environment-based values keep local, staging, and production settings separate without code changes.
- Is hyperf/redis coroutine-safe for high-concurrency workloads?
- Yes. The component is designed for Hyperf's coroutine environment and uses connection pooling so concurrent coroutines do not block each other on a single shared Redis socket. You should still use the provided pool and factory rather than manually sharing raw connections across coroutines. Proper pool sizing and timeouts are important for sustained high-concurrency performance.
- What Redis features does hyperf/redis support?
- It supports common Redis commands, connection pooling, multiple connections, pub/sub, Lua scripting, pipelines, and transactions. These features are exposed through a coroutine-friendly client that integrates with Hyperf's dependency injection and configuration system. That makes it suitable for caching, queues, real-time messaging, and other high-concurrency Redis use cases.
- Can I use multiple Redis connections and environment-based configuration with hyperf/redis?
- Yes. You can define multiple named Redis connections in Hyperf's configuration and select the appropriate one for each service or use case. Environment-based configuration lets you switch hosts, credentials, databases, and pool settings per deployment. This is useful when separating cache, session, queue, and pub/sub workloads.
- How do I test code that uses hyperf/redis?
- Use Hyperf's testing utilities and inject a mocked Redis factory or connection where possible so unit tests do not depend on a live server. For integration tests, run a real Redis instance in Docker or CI and point a test-specific connection configuration at it. Keep production credentials and data out of tests, and assert pool and timeout behavior separately if your application depends on it.
- What production concerns should I watch with hyperf/redis?
- Tune pool minimum and maximum sizes, connection timeouts, and read/write timeouts to match your concurrency and Redis capacity. Watch for pool exhaustion, slow commands, and long-lived pub/sub connections that can consume resources. Use monitoring and sensible retry or failure handling, and avoid running blocking or expensive Redis operations inside hot coroutine paths.
- What are alternatives to hyperf/redis?
- Within Hyperf, hyperf/redis is the natural Redis component because it is built for coroutine safety and framework integration. Alternatives include using the phpredis extension directly with careful coroutine handling or integrating another coroutine-compatible Redis client. Laravel projects would typically use Laravel's Redis integration with predis or phpredis instead.
- How is hyperf/redis maintained and which Hyperf versions are supported?
- hyperf/redis is part of the Hyperf package ecosystem and its releases track Hyperf framework compatibility. Check Packagist and the package's composer constraints for the supported PHP and Hyperf versions before upgrading. Review release notes for breaking changes, especially around configuration, pooling, or coroutine behavior.