Key points
- What it is:
redi.phpis an open-source PHP library (by developerlinkerlin) that aims to be a pure PHP equivalent of Java's Redisson, providing high-level distributed data structures over Redis rather than a raw command interface. - Core compatibility claim: Per its
composer.json, it aims for full cross-language compatibility with data structures created by Redisson, enabling PHP services to interoperate with Java services in heterogeneous microservice architectures (e.g., a PHP script acquiring a lock created by a Java service via Redisson). - Feature set: Distributed Map (RMap), Set (RSet), List (RList), Queue / BlockingQueue, reentrant distributed Lock (RLock) with auto-expiry, Semaphore, AtomicLong, and Pub/Sub — built on Redis atomic commands and Lua scripts for atomicity.
- Tech requirements: PHP ≥ 7.4; depends on the
ext-redisC extension (any version,*), which handles low-level network I/O for performance while high-level logic stays in PHP. - Hybrid design: "high-level logic in PHP, low-level communication in C" — easy Composer-based deployment plus acceptable performance, avoiding Predis-style pure-PHP networking overhead.
- Probable module layout: connection management, distributed objects (per-class files like
RMap.php,RLock.php), a serialization layer that must mirror Redisson's encoding (e.g., JSON in Redis Hashes), and utilities. - Compatibility challenges: matching Redisson's API shapes *and* its serialization formats so data written by either library is readable by the other.
- No actual static scan was performed; recommended tooling includes PHPStan, Psalm, RIPS, SonarQube. Watch for command/Lua injection if lock keys or values come from user input.
- Inherited risk: since it mirrors Redisson, historical Java-side vulnerabilities like CVE-2023-42809 (deserialization-related RCE) warrant scrutiny; avoid PHP native
unserialize()on Redis data and prefer whitelisting or safe formats (JSON/MessagePack). - Server hardening: strong
requirepass,bindto internal IPs, rename/disable dangerous commands (FLUSHALL,CONFIG), enable protected mode, use TLS (rediss://), and prefer Redis 6+ ACLs with least-privilege per-service users. - Audit
ext-redisCVEs and runcomposer audit/ Dependabot on dependencies. - Connection pooling, retry with exponential backoff, idempotent retryable operations, and network-failure handling matter; Redisson's own pitfalls (connection storms on failover, retry not switching channels) are instructive cautionary examples.
- Distributed locks for order processing/inventory; task queues via blocking queues; distributed cache/session storage via RMap/RBucket; real-time pub/sub analytics and atomic counters for PV/UV.
- Install: PHP 7.4+, enable
ext-redis, thencomposer require linkerlin/redi.php. Keep credentials in env/config, not code. - Production: deploy Redis Sentinel or Cluster for HA, colocate PHP and Redis in the same intranet, monitor with
redis-cli infoor Prometheus + Grafana. - Risks: unproven performance vs phpredis, inherited Redisson security concerns, limited community maturity/documentation, hard dependency on ext-redis.
- Suggested roadmap: publish benchmarks, prioritize security hardening against Redisson CVE patterns, build Laravel/Symfony integrations, improve retry/reconnect robustness, and grow community docs.
Architecture analysis
Comparison with other PHP Redis clients
| Aspect | redi.php | phpredis (C ext) | Predis (pure PHP) | |---|---|---|---| | Abstraction level | High-level distributed objects | Raw Redis commands | Raw commands + sharding | | Performance | Higher (via ext-redis), below phpredis | Highest | Lowest (up to ~10x slower in benchmarks) | | Deployment | Composer + ext-redis required | Must compile/install extension | Composer only | | Best for | Distributed systems, Java interop | Raw speed | Environments without C extensions |
Benchmark data (100k/500k set + expire): phpredis 16s/79s vs Predis 21s/104s; with pipelining phpredis drops to 2s/12s (~8x speedup). redi.php's own benchmarks are not published.