定制 pardnchiu/redis-cli 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pardnchiu/redis-cli

Composer 安装命令:

composer require pardnchiu/redis-cli

包简介

Lightweight PHP Redis client supporting cache operations, automatic connection management, and complete Redis functionality. Built on native Redis extension, providing stable and reliable cache operation experience.

README 文档

README

Lightweight PHP Redis client supporting cache operations, automatic connection management, and complete Redis functionality.
Built on native Redis extension, providing stable and reliable cache operation experience.

packagist version license
readme readme

Three Core Features

Automatic Connection Management

Intelligent connection pool management, automatically establishes and maintains Redis connections, supports persistent connections for improved performance

Multi-Database Support

Flexible database selection mechanism, supports Redis multi-database operations to meet different business scenario requirements

Stable Connection

Built-in retry mechanism and error handling, ensuring reliability in unstable network environments

Features

  • Environment Variable Configuration: Flexible environment variable settings, supports multi-environment deployment
  • Persistent Connections: Uses persistent connections to improve performance and reduce connection overhead
  • Automatic Retry: Built-in retry mechanism handles network fluctuations and temporary connection failures
  • Complete Redis Operations: Supports Redis data types including strings, hashes, lists, sets, etc.
  • Multi-Database Support: Supports Redis multi-database operations, flexible management of different business data
  • Security Authentication: Supports password authentication to ensure connection security
  • Stateless Design: Automatic connection management and cleanup

Usage

Installation

composer require pardnchiu/redis-cli

Environment Configuration

REDIS_HOST=localhost      # Redis host address
REDIS_PORT=6379           # Redis port
REDIS_PASSWORD=your_pass  # Redis password (optional)

Basic Usage

<?php

use pardnchiu\RDB;

// Initialize client
$redis = new RDB();

// Basic string operations
$redis->set(0, "user:123", "John Doe", 3600);  // Set value with expiration
$user = $redis->get(0, "user:123");            // Get value

// Check connection status
if ($redis->isConnected()) {
    echo "Redis connection is normal";
}

// Counter operations
$redis->incr(0, "page_views");
$redis->decr(0, "stock_count");

API Reference

Basic Operations

  • get($db, $key) - Get string value

    $value = $redis->get(0, "user:123");
  • set($db, $key, $content, $expire = null) - Set string value

    $redis->set(0, "session:abc", $data, 1800);  // 30 minutes expiration
    $redis->set(1, "config:app", $config);        // Never expires
  • exists($db, $key) - Check if key exists

    if ($redis->exists(0, "user:123")) {
        echo "User exists";
    }
  • delete($db, $key) - Delete key

    $redis->delete(0, "temp:data");
  • ttl($db, $key) - Get expiration time

    $seconds = $redis->ttl(0, "session:abc");
  • keys($db, $pattern) - Search key names

    $userKeys = $redis->keys(0, "user:*");

Hash Operations

// Set hash field
$redis->hset(0, "user:123", "name", "John Doe", 3600);
$redis->hset(0, "user:123", "email", "john@example.com");

// Get hash field
$name = $redis->hget(0, "user:123", "name");

// Get all hash data
$userData = $redis->hgetall(0, "user:123");

List Operations

// Push to list (left/right side)
$redis->lpush(0, "tasks", "New Task", 3600);
$redis->rpush(0, "logs", "Log Message");

// Pop list elements
$task = $redis->lpop(0, "tasks");
$log = $redis->rpop(0, "logs");

// Get list length
$length = $redis->llen(0, "tasks");

Set Operations

// Add set members
$redis->sadd(0, "tags", "php", 3600);
$redis->sadd(0, "tags", "redis");

// Remove set member
$redis->srem(0, "tags", "old_tag");

// Get all members
$tags = $redis->smembers(0, "tags");

// Check member existence
if ($redis->sismember(0, "tags", "php")) {
    echo "Contains PHP tag";
}

// Set operations
$common = $redis->sinter(0, ["tags:user1", "tags:user2"]);  // Intersection
$all = $redis->sunion(0, ["tags:user1", "tags:user2"]);     // Union
$diff = $redis->sdiff(0, ["tags:user1", "tags:user2"]);     // Difference

Management Operations

// Batch operations
$values = $redis->mget(0, ["key1", "key2", "key3"]);
$redis->mset(0, ["key1" => "value1", "key2" => "value2"]);

// Numeric operations
$redis->incr(0, "counter");         // Increment by 1
$redis->decr(0, "stock");           // Decrement by 1
$redis->append(0, "log", "New content"); // Append string

// Clear database
$redis->flushdb(0);

// Get server info
$info = $redis->info();

Error Handling

try {
    $redis = new RDB();
    
    // Redis operations
    $result = $redis->set(0, "user:123", $userData, 3600);
    
    if ($result) {
        echo "Data saved successfully";
    } else {
        echo "Data save failed";
    }
    
} catch (\Exception $e) {
    // Connection error handling
    error_log("Redis error: " . $e->getMessage());
    
    if (strpos($e->getMessage(), "Connection refused") !== false) {
        echo "Redis server is not running";
    } elseif (strpos($e->getMessage(), "Authentication") !== false) {
        echo "Redis authentication failed, please check password";
    } else {
        echo "Redis operation exception, please try again later";
    }
}

Connection Status Check

$redis = new RDB();

// Check connection status
if (!$redis->isConnected()) {
    // Handle connection failure
    error_log("Redis connection failed, using fallback solution");
    
    // Can use other cache solutions or directly query database
    return $this->fallbackCache($key);
}

// Normal Redis usage
$data = $redis->get(0, $key);

Performance Monitoring

// Monitor connection status
$info = $redis->info();
if ($info) {
    $connectedClients = $info['connected_clients'] ?? 0;
    $usedMemory = $info['used_memory_human'] ?? '0B';
    
    error_log("Redis status - Connections: {$connectedClients}, Memory usage: {$usedMemory}");
}

License

This project is licensed under the MIT License.

Author

邱敬幃 Pardn Chiu

©️ 2024 邱敬幃 Pardn Chiu

pardnchiu/redis-cli 适用场景与选型建议

pardnchiu/redis-cli 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「redis」 「php」 「cache」 「session」 「pardnchiu」 「邱敬幃」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 pardnchiu/redis-cli 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pardnchiu/redis-cli 我们能提供哪些服务?
定制开发 / 二次开发

基于 pardnchiu/redis-cli 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-24