- Can I use yiisoft/yii2-redis as the Redis driver in a Laravel application?
- No. yiisoft/yii2-redis is the official Redis extension for Yii 2, not Laravel. It does not register a Laravel service provider, publish Laravel config, or implement Illuminate contracts. Requiring it in a Laravel app would pull in Yii 2 dependencies without providing a usable Laravel Redis driver. Use Laravel's built-in Redis component or predis/predis instead.
- How do I install yiisoft/yii2-redis with Composer?
- Run composer require --prefer-dist yiisoft/yii2-redis:~2.1.0, or add "yiisoft/yii2-redis": "~2.1.0" to your composer.json require section. The package requires PHP 7.4 or later and works best with PHP 8. It is intended for Yii 2 applications, not Laravel.
- How do I configure the Redis connection in Yii 2?
- Configure a redis component in your Yii 2 application config with hostname, port, database, password, and other connection options. Then assign the package's Cache, Session, Mutex, and ActiveRecord components to use that connection. Most cache and session swaps require only component assignment changes, not application-code changes.
- What Redis features does yii2-redis provide for Yii 2?
- It provides a Redis connection and command layer, a cache backend, session storage, distributed mutex locking, and an ActiveRecord implementation for storing structured data. The Predis-backed connection adds standalone, Sentinel, and cluster topologies with retry and backoff support. However, cluster mode does not support the Cache, Session, ActiveRecord, or Mutex component interfaces.
- Does yii2-redis ActiveRecord support joins, ORDER BY, limit, or offset?
- No. The Redis ActiveRecord is a lookalike, not a drop-in replacement for yii db ActiveRecord. It does not support limit(), offset(), orderBy(), indexBy(), or relations declared through a join table. Query patterns copied from SQL ActiveRecord can silently return unbounded result sets or fail. Use it for simple key-based models, not paginated relational queries.
- What PHP and Redis versions does yiisoft/yii2-redis require?
- The minimum PHP version is 7.4, and the package works best with PHP 8. Redis 2.6.12 or later is required for all components to work properly. The README does not explicitly document Redis 6 ACL username handling or RESP3 behavior, so verify those against your Redis 7.x deployment.
- Is yii2-redis compatible with Redis Cluster or Sentinel?
- The Predis connection supports standalone, Sentinel, and cluster topologies, with an explicit exponential-backoff retry strategy. Sentinel is the safer fit for full component use. The Predis cluster connection does not support the Cache, Session, ActiveRecord, or Mutex component interfaces, so cluster mode gives you raw key-value access only and forfeits the package's main features.
- Can I use yii2-redis for sessions and cache in production?
- Yes, within a Yii 2 application, but Redis cache and session data are volatile by default. An eviction policy such as allkeys-lru can evict session data under memory pressure. Configure Redis eviction and persistence carefully, and consider separate Redis instances or databases for cache versus sessions. TLS is supported through SSL options or the tls scheme.
- How should I test a Yii 2 app that uses yii2-redis?
- Use a real disposable Redis instance or container in integration tests, because this package is a connection and command integration layer. Mocking the Redis connection can miss command behavior, eviction, and query constraints. Test cache, session, mutex, and ActiveRecord behavior separately. The repository includes build, static analysis, and Codecov badges for its own test coverage.
- Is yiisoft/yii2-redis still maintained, and what are the alternatives?
- It is the official Yii core team Redis integration for Yii 2, with build, static analysis, and coverage signals, but Yii 2 overall is in maintenance-mode territory relative to Yii 3. For Laravel, use Laravel's built-in Redis component or predis/predis; yii2-redis is not applicable there. For Yii 2, this package is the official path, while predis/predis is the common lower-level alternative for raw Redis access.