snipershady/redis-information-analyzer
Composer 安装命令:
composer require snipershady/redis-information-analyzer
包简介
Software to analyze redis performances
README 文档
README
A powerful PHP library to analyze and monitor Redis server performance and statistics. This library provides an elegant object-oriented interface to retrieve and analyze Redis information with strongly-typed DTOs.
Features
- Comprehensive Redis server information retrieval
- Strongly-typed DTOs for all Redis INFO sections
- Detailed connected clients list with full metadata
- Memory usage and fragmentation analysis
- Performance statistics and hit rate monitoring
- Replication status tracking
- Persistence (RDB/AOF) monitoring
- CPU usage metrics
- Built-in web dashboard for visualization
- Singleton connection management
- Full PHP 8.2+ type safety
Requirements
- PHP >= 8.2
- Redis server
- PHP Redis extension (
ext-redis) - Predis library
Installation
Install the library via Composer:
composer require snipershady/redis-information-analyzer
Quick Start
Basic Usage
<?php require_once __DIR__ . '/vendor/autoload.php'; use RedisAnalizer\Service\RedisInformationRetriever; // Create retriever instance $retriever = new RedisInformationRetriever(); // Get all Redis information at once $allInfo = $retriever->getAllInfo(); // Access specific sections echo "Redis Version: " . $allInfo['server']->getRedisVersion() . "\n"; echo "Used Memory: " . $allInfo['memory']->getUsedMemoryHuman() . "\n"; echo "Connected Clients: " . $allInfo['clients']->getConnectedClients() . "\n";
Retrieving Specific Information
Server Information
$serverInfo = $retriever->getServerInfo(); echo "Redis Version: " . $serverInfo->getRedisVersion() . "\n"; echo "Redis Mode: " . $serverInfo->getRedisMode() . "\n"; echo "OS: " . $serverInfo->getOs() . "\n"; echo "Uptime: " . $serverInfo->getUptimeInDays() . " days\n"; echo "TCP Port: " . $serverInfo->getTcpPort() . "\n";
Memory Information
$memoryInfo = $retriever->getMemoryInfo(); echo "Used Memory: " . $memoryInfo->getUsedMemoryHuman() . "\n"; echo "Peak Memory: " . $memoryInfo->getUsedMemoryPeakHuman() . "\n"; echo "Fragmentation Ratio: " . $memoryInfo->getMemFragmentationRatio() . "\n"; if ($memoryInfo->isFragmented()) { echo "Warning: High memory fragmentation detected!\n"; }
Statistics
$statsInfo = $retriever->getStatsInfo(); echo "Total Commands: " . number_format($statsInfo->getTotalCommandsProcessed()) . "\n"; echo "Ops/Second: " . $statsInfo->getInstantaneousOpsPerSec() . "\n"; echo "Hit Rate: " . $statsInfo->getHitRate() . "%\n"; echo "Keyspace Hits: " . number_format($statsInfo->getKeyspaceHits()) . "\n"; echo "Keyspace Misses: " . number_format($statsInfo->getKeyspaceMisses()) . "\n";
Connected Clients
// Get connected clients count $numberOfClients = $retriever->getNumberOfConnection(); echo "Connected clients: {$numberOfClients}\n"; // Get detailed client list $clientList = $retriever->getClientList(); foreach ($clientList as $client) { echo "Client #{$client->getId()}\n"; echo " Address: {$client->getAddr()}\n"; echo " Name: " . ($client->getName() ?? 'unnamed') . "\n"; echo " Age: {$client->getAge()}s\n"; echo " Idle: {$client->getIdle()}s\n"; echo " Database: {$client->getDb()}\n"; echo " Last Command: " . ($client->getCmd() ?? 'N/A') . "\n"; echo " Memory: {$client->getTotalMemoryKB()} KB\n"; echo "\n"; }
Clients Summary Information
$clientsInfo = $retriever->getClientsInfo(); echo "Connected Clients: " . $clientsInfo->getConnectedClients() . "\n"; echo "Max Clients: " . $clientsInfo->getMaxclients() . "\n"; echo "Blocked Clients: " . $clientsInfo->getBlockedClients() . "\n"; echo "Client Usage: " . $clientsInfo->getClientUsagePercentage() . "%\n";
CPU Information
$cpuInfo = $retriever->getCpuInfo(); echo "System CPU: " . $cpuInfo->getUsedCpuSys() . "s\n"; echo "User CPU: " . $cpuInfo->getUsedCpuUser() . "s\n"; echo "Total CPU: " . $cpuInfo->getTotalCpuUsed() . "s\n";
Keyspace Information
$keyspaceInfo = $retriever->getKeyspaceInfo(); echo "Total Databases: " . $keyspaceInfo->getDatabaseCount() . "\n"; echo "Total Keys: " . number_format($keyspaceInfo->getTotalKeys()) . "\n"; echo "Total Expires: " . number_format($keyspaceInfo->getTotalExpires()) . "\n"; foreach ($keyspaceInfo->getDatabases() as $dbNumber => $dbInfo) { echo "\nDatabase {$dbNumber}:\n"; echo " Keys: {$dbInfo['keys']}\n"; echo " Expires: {$dbInfo['expires']}\n"; echo " Avg TTL: {$dbInfo['avg_ttl']} ms\n"; }
Replication Information
$replicationInfo = $retriever->getReplicationInfo(); echo "Role: " . $replicationInfo->getRole() . "\n"; if ($replicationInfo->isMaster()) { echo "Connected Slaves: " . $replicationInfo->getConnectedSlaves() . "\n"; echo "Replication Offset: " . $replicationInfo->getMasterReplOffset() . "\n"; } else { echo "Master Host: " . $replicationInfo->getMasterHost() . "\n"; echo "Master Port: " . $replicationInfo->getMasterPort() . "\n"; echo "Link Status: " . $replicationInfo->getMasterLinkStatus() . "\n"; echo "Connected: " . ($replicationInfo->isReplicaConnected() ? 'Yes' : 'No') . "\n"; }
Persistence Information
$persistenceInfo = $retriever->getPersistenceInfo(); // RDB (Snapshot) information echo "RDB Last Save: " . $persistenceInfo->getRdbLastSaveTimeFormatted() . "\n"; echo "Changes Since Last Save: " . $persistenceInfo->getRdbChangesSinceLastSave() . "\n"; echo "Last Save Status: " . $persistenceInfo->getRdbLastBgsaveStatus() . "\n"; echo "RDB Save in Progress: " . ($persistenceInfo->isRdbSaveInProgress() ? 'Yes' : 'No') . "\n"; // AOF information if ($persistenceInfo->isAofEnabled()) { echo "\nAOF Enabled: Yes\n"; echo "AOF Current Size: " . number_format($persistenceInfo->getAofCurrentSize()) . " bytes\n"; echo "AOF Rewrite in Progress: " . ($persistenceInfo->isAofRewriteInProgress() ? 'Yes' : 'No') . "\n"; } else { echo "\nAOF Enabled: No\n"; }
Monitoring Example
<?php require_once __DIR__ . '/vendor/autoload.php'; use RedisAnalizer\Service\RedisInformationRetriever; $retriever = new RedisInformationRetriever(); $allInfo = $retriever->getAllInfo(); // Check memory fragmentation if ($allInfo['memory']->isFragmented()) { echo "[WARNING] High memory fragmentation detected: " . $allInfo['memory']->getMemFragmentationRatio() . "\n"; } // Check hit rate $hitRate = $allInfo['stats']->getHitRate(); if ($hitRate < 80) { echo "[WARNING] Low hit rate: {$hitRate}%\n"; echo "Consider reviewing your caching strategy.\n"; } // Check client usage $clientUsage = $allInfo['clients']->getClientUsagePercentage(); if ($clientUsage > 80) { echo "[WARNING] High client usage: {$clientUsage}%\n"; echo "Current: {$allInfo['clients']->getConnectedClients()} / " . "{$allInfo['clients']->getMaxclients()}\n"; } // Check persistence status if ($allInfo['persistence']->getRdbLastBgsaveStatus() !== 'ok') { echo "[ERROR] Last RDB save failed!\n"; }
Web Dashboard
The library includes a ready-to-use web dashboard for visualizing Redis information.
Setup Web Dashboard
- Point your web server to the
publicdirectory:
cd public
php -S localhost:8080
- Open your browser and navigate to
http://localhost:8080
The dashboard displays:
- Server information
- Memory usage and fragmentation
- Statistics and performance metrics
- CPU usage
- Connected clients summary
- Detailed client list with all metadata
- Keyspace information
- Replication status
- Persistence (RDB/AOF) status
Custom Implementation
You can also integrate the library into your own application:
<?php require_once __DIR__ . '/../vendor/autoload.php'; $retriever = new RedisAnalizer\Service\RedisInformationRetriever(); $allInfo = $retriever->getAllInfo(); $clientList = $retriever->getClientList(); // Use the data in your application // $allInfo contains all Redis information // $clientList contains detailed client information
Configuration
Custom Redis Connection
By default, the library connects to redis-server:6379. To customize the connection, modify the RedisConnection class or extend it:
<?php namespace RedisAnalizer\Service; use Predis\Client; class RedisConnection { private static ?RedisConnection $redisConnection = null; private function __construct( string $server = 'localhost', // Change default host int $port = 6379, // Change default port string $connectionIdentifier = 'redis-analyzer-predis01', bool $isPersistent = true ) { // Connection configuration } }
API Reference
RedisInformationRetriever
Main class for retrieving Redis information.
Methods
getAllInfo(): array- Get all Redis information sectionsgetServerInfo(): ServerDto- Get server informationgetMemoryInfo(): MemoryDto- Get memory informationgetStatsInfo(): StatsDto- Get statisticsgetCpuInfo(): CpuDto- Get CPU informationgetClientsInfo(): ClientsDto- Get clients summarygetKeyspaceInfo(): KeyspaceDto- Get keyspace informationgetReplicationInfo(): ReplicationDto- Get replication informationgetPersistenceInfo(): PersistenceDto- Get persistence informationgetClientList(): array- Get detailed list of connected clientsgetNumberOfConnection(): int- Get number of connected clients
Available DTOs
Each DTO provides typed getter methods for accessing Redis information:
ServerDto- Server and system informationMemoryDto- Memory usage and fragmentationStatsDto- Performance statisticsCpuDto- CPU usage metricsClientsDto- Clients summary informationKeyspaceDto- Database and keys informationReplicationDto- Replication statusPersistenceDto- RDB and AOF persistence statusRedisClientInfo- Individual client detailed information
Development
Code Quality Tools
# Run all quality checks composer quality-check # Fix code style composer cs-fix # Run static analysis composer phpstan # Run Rector composer rector
Requirements for Development
- PHP >= 8.2
- Composer
- PHP-CS-Fixer
- PHPStan
- Rector
License
This project is licensed under the GPL-2.0 License - see the LICENSE file for details.
Author
Stefano Perrini
- Homepage: https://www.spinfo.it
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For bugs, feature requests, or questions, please open an issue on the GitHub repository.
snipershady/redis-information-analyzer 适用场景与选型建议
snipershady/redis-information-analyzer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 205 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「redis info」 「redis analyzer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 snipershady/redis-information-analyzer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 snipershady/redis-information-analyzer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 snipershady/redis-information-analyzer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
(ru) language pack for the Static Info Tables providing localized names for countries, currencies and so on.
Log analyzer widget for yii2
Microservice RPC through message queues.
The CodeIgniter Redis package
Runtime analysis tool for Doctrine ORM integrated into Symfony Web Profiler. Unlike static linters, it analyzes actual query execution at runtime to detect performance bottlenecks, security vulnerabilities, and best practice violations during development with real execution context and data.
Turkish (tr) language pack for the Static Info Tables providing localized names for countries.
统计信息
- 总下载量: 205
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2026-01-09
