felconca/redis-cache
最新稳定版本:v1.1
Composer 安装命令:
composer require felconca/redis-cache
包简介
Lightweight pure PHP Redis client without native extensions (no redis.dll required).
README 文档
README
Lightweight pure PHP Redis client without native extensions
Works without redis.dll or the PHP Redis extension. Supports all Redis commands, pipelines, transactions, authentication, database selection, and optional JSON serialization.
📦 Installation
Use Composer to install:
composer require felconca/redis-cache
Composer will handle autoloading, so you can start using it immediately.
⚡ Usage
Basic Usage
<?php require 'vendor/autoload.php'; use Redis\RedisCache; // Create a Redis client $redis = new RedisCache([ 'host' => '127.0.0.1', 'port' => 6379, 'password' => null, // optional, leave null if no password 'database' => 0, // optional, default DB 'timeout' => 2, // optional timeout in seconds 'json' => true, // optional: automatically serialize/deserialize arrays ]); // Ping Redis echo $redis->ping(); // PONG // Set a key $redis->set('foo', ['name' => 'Alice', 'age' => 30]); // Get a key print_r($redis->get('foo')); // ['name' => 'Alice', 'age' => 30] // Delete a key $redis->del('foo');
Pipelines
$redis->pipelineStart(); $redis->set('a', 1); $redis->set('b', 2); $redis->get('a'); $redis->get('b'); $responses = $redis->pipelineExecute(); print_r($responses); // Responses from all commands
Transactions
$redis->multi(); $redis->set('x', 100); $redis->set('y', 200); $responses = $redis->exec(); print_r($responses); // Results of transaction
Advanced Options
- AUTH: Provide
'password' => 'yourpassword'to connect to protected Redis. - SELECT DB: Provide
'database' => 2to select a database other than 0. - JSON mode: Set
'json' => trueto automatically serialize arrays and decode them on retrieval. - Timeout: Set
'timeout' => 2to change connection timeout (seconds). - Auto-reconnect: Enabled by default. Handles connection drops automatically.
Example with All Options
$redis = new RedisCache([ 'host' => '127.0.0.1', 'port' => 6379, 'password' => 'myStrongPassword', 'database' => 1, 'timeout' => 3, 'json' => true ]); $redis->set('user:1', ['name' => 'Bob', 'role' => 'admin']); print_r($redis->get('user:1'));
Closing the Connection
$redis->close();
✅ Features
- No PHP extensions required (
redis.dllnot needed) - Supports all Redis commands dynamically
- Pipelines & Transactions
- Authentication & database selection
- JSON serialization/deserialization
- Configurable timeout and auto-reconnect
- Lightweight and pure PHP
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-13