pardnchiu / redis
PD\Redis is a PHP Redis client wrapper built on Predis, offering simplified Redis operations with automatic connection management.
1.0.0
2025-02-02 20:41 UTC
Requires
- php: >=8.0
- predis/predis: ^2.0
README
PD\Redis is a PHP Redis client wrapper built on Predis, offering simplified Redis operations with automatic connection management.
Features
- Automatic connection management
- Environment-based configuration
- Persistent connection support
- Automatic database selection
- Built-in error handling
- Connection state monitoring
- Automatic cleanup on destruction
Key Capabilities
- Simple get/set operations with database selection
- Automatic connection retry mechanism
- Expiration time management
- Connection status checking
- Environment variables configuration
- Persistent connection support
Required Environment Variables
REDIS_HOST=localhost # Required: Redis server host REDIS_PORT=6379 # Required: Redis server port REDIS_PASSWORD=secret # Optional: Redis server password
How to Use
Install
composer require pardnchiu/redis
// Initialize Redis client $redis = new PD\Redis(); // Set value with expiration $redis->set(0, "user:123", "user_data", 3600); // db 0, expires in 1 hour // Get value $data = $redis->get(0, "user:123"); // from db 0 // Check connection status if ($redis->isConnected()) { // Redis is connected and ready }
License
This source code project is licensed under the MIT license.
Creator
邱敬幃 Pardn Chiu
©️ 2024 邱敬幃 Pardn Chiu