valkey-io/valkey-glide-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

valkey-io/valkey-glide-php

Composer 安装命令:

pie install valkey-io/valkey-glide-php

包简介

Valkey GLIDE for PHP

README 文档

README

GLIDE is the official open-source Valkey client library, proudly part of the Valkey organization. Our mission is to make your experience with Valkey and Redis OSS seamless and enjoyable. Whether you're a seasoned developer or just starting out, Valkey GLIDE is here to support you every step of the way.

valkey-glide-php is the PHP binding for Valkey GLIDE. It brings the power and flexibility of the Valkey GLIDE core to the PHP ecosystem, with a familiar and convenient interface based on the popular PHPRedis API. By providing a drop-in replacement client for PHPRedis, this client offers an easy migration path and minimal learning curve—while adding the features of Valkey GLIDE.

Why Choose Valkey GLIDE?

  • Community and Open Source: Join our vibrant community and contribute to the project. We are always here to respond, and the client is for the community.
  • Reliability: Built with best practices learned from over a decade of operating Redis OSS-compatible services.
  • Performance: Optimized for high performance and low latency.
  • High Availability: Designed to ensure your applications are always up and running.
  • Cross-Language Support: Implemented using a core driver framework written in Rust, with language-specific extensions to ensure consistency and reduce complexity.
  • Stability and Fault Tolerance: We brought our years of experience to create a bulletproof client.
  • Backed and Supported by AWS and GCP: Ensuring robust support and continuous improvement of the project.

Key Features

Experimental Features

  • Compression – The compression feature is currently experimental. We are actively expanding this feature, and detailed documentation around risks and usage will be updated soon.

Supported Engine Versions

Valkey GLIDE is API-compatible with the following engine versions:

Engine Type 6.2 7.0 7.1 7.2 8.0 8.1 9.0
Valkey - - - V V V V
Redis V V V V - - -

Getting Started - PHP Wrapper

System Requirements

The release of Valkey GLIDE was tested on the following platforms:

Linux:

  • Ubuntu 20 (x86_64/amd64 and arm64/aarch64)

Note: Currently Alpine Linux / MUSL is NOT supported.

macOS:

  • macOS 14.7 (Apple silicon/aarch_64)

PHP Supported Versions

PHP Version
8.2
8.3

Installation and Setup

Prerequisites

Before installing Valkey GLIDE PHP extension, ensure you have the following dependencies:

  • PHP development headers (php-dev or php-devel)
  • Build tools (gcc, make, autotools)
  • Git
  • pkg-config
  • protoc (protobuf compiler) >= v3.20.0
  • openssl and openssl-dev
  • rustup (Rust toolchain)
  • php-bcmath (Protobuf PHP dependency, needed only for testing)

Installing Dependencies

Ubuntu/Debian:

sudo apt update -y
sudo apt install -y php-dev php-cli git gcc make autotools-dev pkg-config openssl libssl-dev unzip php-bcmath
# Install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"

CentOS/RHEL:

sudo yum update -y
sudo yum install -y php-devel php-cli git gcc make pkgconfig openssl openssl-devel unzip php-bcmath
# Install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"

macOS:

brew update
brew install php git gcc make pkgconfig protobuf openssl
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"

Installing protobuf compiler

For macOS:

brew install protobuf
brew install protobuf-c
# Verify installation
protoc --version

For Linux:

PB_REL="https://github.com/protocolbuffers/protobuf/releases"
curl -LO $PB_REL/download/v3.20.3/protoc-3.20.3-linux-x86_64.zip
unzip protoc-3.20.3-linux-x86_64.zip -d $HOME/.local
export PATH="$PATH:$HOME/.local/bin"
# Verify installation (minimum version 3.20.0 required)
protoc --version

Installing from Packagist

You can use pie to install the extension from the Packagist repository. See: https://packagist.org/packages/valkey-io/valkey-glide-php

Before starting this step, make sure you've installed all dependencies above.

Additionally, you will need to install the pie tool.

On Linux, you can download pie with curl. eg:

curl -L https://github.com/php/pie/releases/latest/download/pie.phar -o pie
chmod +x pie
sudo mv pie /usr/local/bin/pie
export PATH="$PATH:/usr/local/bin"

On MacOS, install with Homebrew:

brew install pie

To install the Valkey Glide extension, simply use the pie command:

# VERSION can be set to any release tag or branch at https://github.com/valkey-io/valkey-glide-php.git
export VERSION=1.0.0
pie install valkey-io/valkey-glide-php:$VERSION

Installing from PECL

You can install the extension using PECL from GitHub releases:

# Download the package
curl -L https://github.com/valkey-io/valkey-glide-php/releases/download/v1.0.0/valkey_glide-1.0.0.tgz -o valkey_glide-1.0.0.tgz

# Install with PECL
pecl install valkey_glide-1.0.0.tgz

After installation, add the extension to your php.ini:

extension=valkey_glide

Verify the installation:

php -m | grep valkey_glide
php -r "if (extension_loaded('valkey_glide')) echo 'SUCCESS: Extension loaded!'; else echo 'ERROR: Extension not loaded';"

Building and Installing the Extension from source

  1. Clone the repository:

    git clone --recurse-submodules https://github.com/valkey-io/valkey-glide-php.git
    cd valkey-glide-php
  2. Initialize submodules (if not cloned with --recurse-submodules):

    git submodule update --init --recursive
  3. Build the FFI library (required dependency):

    python3 utils/patch_proto_and_rust.py
    cd valkey-glide/ffi
    cargo build --release
    cd ../../
  4. Build the extension:

    phpize
    ./configure --enable-valkey-glide
    make build-modules-pre
    make install
  5. Enable the extension by adding it to your php.ini file:

    extension=valkey_glide
  6. Generate PHP protobuf classes used for testing purposes:

    protoc --proto_path=./valkey-glide/glide-core/src/protobuf --php_out=./tests/ ./valkey-glide/glide-core/src/protobuf/connection_request.proto
  7. Install PHP dependencies with composer:

    composer install --no-interaction --prefer-dist --optimize-autoloader
  8. Execute the tests:

    make test

Basic Examples

Standalone Valkey

// Create ValkeyGlide client
$client = new ValkeyGlide();
$client->connect(addresses: [['host' => 'localhost', 'port' => 6379]]);

// Basic operations
$setResult = $client->set('foo', 'bar');
echo "SET result: " . $setResult . "\n";

$getValue = $client->get('foo');
echo "GET result: " . $getValue . "\n";

$pingResult = $client->ping();
echo "PING result: " . $pingResult . "\n";

// Close the connection
$client->close();

PHPRedis-Compatible Class Names

For easier migration from PHPRedis, you can use PHPRedis-compatible class names:

Standalone:

// Register PHPRedis compatibility aliases
ValkeyGlide::registerPHPRedisAliases();

// Now you can use Redis instead of ValkeyGlide
$client = new Redis();
$client->connect(addresses: [['host' => 'localhost', 'port' => 6379]]);

$client->set('foo', 'bar');
$value = $client->get('foo');

// Exceptions are also aliased
try {
    // Operations that may fail
} catch (RedisException $e) {
    echo "Caught RedisException: " . $e->getMessage() . "\n";
}

$client->close();

Cluster:

// Register PHPRedis compatibility aliases
ValkeyGlide::registerPHPRedisAliases();

// Now you can use RedisCluster instead of ValkeyGlideCluster
$cluster = new RedisCluster(
    addresses: [
        ['host' => 'localhost', 'port' => 7001],
        ['host' => 'localhost', 'port' => 7002]
    ]
);

$cluster->set('foo', 'bar');
$value = $cluster->get('foo');

$cluster->close();

Requirements:

  • PHP 8.3 or higher (required for class_alias() support with internal classes)

With IAM Authentication for AWS ElastiCache

// Create ValkeyGlide client with IAM authentication.
$client = new ValkeyGlide();
$client->connect(
    addresses: [['host' => 'my-cluster.xxxxx.use1.cache.amazonaws.com', 'port' => 6379]],
    use_tls: true,  // REQUIRED for IAM authentication
    credentials: [
        'username' => 'my-iam-user',  // REQUIRED for IAM
        'iamConfig' => [
            ValkeyGlide::IAM_CONFIG_CLUSTER_NAME => 'my-cluster',
            ValkeyGlide::IAM_CONFIG_REGION => 'us-east-1',
            ValkeyGlide::IAM_CONFIG_SERVICE => ValkeyGlide::IAM_SERVICE_ELASTICACHE,
            ValkeyGlide::IAM_CONFIG_REFRESH_INTERVAL => 300  // Optional, defaults to 300 seconds
        ]
    ]
);

// Use the client normally - IAM tokens are managed automatically
$client->set('key', 'value');
$value = $client->get('key');
echo "Value: " . $value . "\n";

$client->close();

With TLS

// Create ValkeyGlide client with TLS configuration
$client = new ValkeyGlide();
$client->connect(
    addresses: [['host' => 'localhost', 'port' => 6379]],
    use_tls: true,
    advanced_config: ['tls_config' => ['root_certs' => $root_certs_data]]
);

// Create ValkeyGlide client with TLS stream context
$client = new ValkeyGlide();
$client->connect(
    addresses: [['host' => 'localhost', 'port' => 6379]],
    context: stream_context_create(['ssl' => 'ca-cert.pem'])   
)

Cluster Valkey

// Create cluster client configuration
$addresses = [
    ['host' => 'localhost', 'port' => 7001],
    ['host' => 'localhost', 'port' => 7002],
    ['host' => 'localhost', 'port' => 7003]
];

// Create ValkeyGlideCluster client with multi-database support (Valkey 9.0+)
$client = new ValkeyGlideCluster(
    addresses: $addresses,
    read_from: ValkeyGlide::READ_FROM_PREFER_REPLICA, 
    database_id: 1 // Requires Valkey 9.0+ with cluster-databases > 1
);

// Basic operations
$setResult = $client->set('foo', 'bar');
echo "SET result: " . $setResult . "\n";

$getValue = $client->get('foo');
echo "GET result: " . $getValue . "\n";

$pingResult = $client->ping();
echo "PING result: " . $pingResult . "\n";

// Close the connection
$client->close();

Building & Testing

Development instructions for local building & testing the package are in the DEVELOPER.md file.

Contributing

GitHub is a platform for collaborative coding. If you're interested in writing code, we encourage you to contribute by submitting pull requests from forked copies of this repository. Additionally, please consider creating GitHub issues for reporting bugs and suggesting new features. Feel free to comment on issues that interest. For more info see Contributing.

All contributions are automatically validated through our CI pipeline, ensuring:

  • Code style compliance
  • All tests passing across supported PHP versions
  • Memory leak detection and performance benchmarks

Get Involved

We invite you to join our open-source community and contribute to Valkey GLIDE. Whether it's reporting bugs, suggesting new features, or submitting pull requests, your contributions are highly valued. Check out our Contributing Guidelines to get started.

If you have any questions or need assistance, don't hesitate to reach out. Open a GitHub issue, and our community and contributors will be happy to help you.

Community Support and Feedback

We encourage you to join our community to support, share feedback, and ask questions. You can approach us for anything on our Valkey Slack: Join Valkey Slack.

License

valkey-io/valkey-glide-php 适用场景与选型建议

valkey-io/valkey-glide-php 是一款 基于 C 开发的 Composer 扩展包,目前已累计 380 次下载、GitHub Stars 达 34, 最近一次更新时间为 2025 年 08 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 valkey-io/valkey-glide-php 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 34
  • Watchers: 1
  • Forks: 12
  • 开发语言: C

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2025-08-26