sinemacula/laravel-valkey-glide
Composer 安装命令:
composer require sinemacula/laravel-valkey-glide
包简介
Laravel Redis driver and adapter for Valkey GLIDE (ext-valkey_glide).
README 文档
README
Laravel Valkey GLIDE is a Laravel-native Redis integration for ext-valkey_glide.
It adds a valkey-glide Redis client driver to Laravel so cache, queue, session, and direct Redis usage can run through
Valkey GLIDE using Laravel's existing Redis abstractions.
Purpose
Managed Redis/Valkey platforms can drop sockets during maintenance, failover, scaling, or node replacement. This package integrates GLIDE into Laravel so reconnect behavior is handled at the client/connection layer rather than in application business code.
What Is Implemented
- Service provider registration of the
valkey-glidedriver viaRedisManager::extend() - Connector implementing
Illuminate\Contracts\Redis\Connector - Connection wrapper extending
Illuminate\Redis\Connections\Connection - Laravel config normalization into GLIDE
connect()arguments - Optional single retry for idempotent commands on transient transport errors
- Key prefix compatibility for supported command families, including key-list handling for
MGET - Laravel compatibility fallback for phpredis-style
SETandEVALcommand argument shapes - External test lane for extension and real Redis connectivity validation
Requirements
- PHP
^8.3 - Laravel components with
illuminate/redis^11.0 || ^12.0 ext-valkey_glidein runtime environments that use this driver
ext-valkey_glide is declared in suggest so this package can still be installed in environments that do not run the
Valkey driver.
Installation
composer require sinemacula/laravel-valkey-glide
Laravel Configuration
Set Redis client in your environment:
REDIS_CLIENT=valkey-glide
Example single-node Redis connection:
'redis' => [ 'client' => env('REDIS_CLIENT', 'valkey-glide'), 'default' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'port' => (int) env('REDIS_PORT', 6379), 'username' => env('REDIS_USERNAME'), 'password' => env('REDIS_PASSWORD'), 'database' => (int) env('REDIS_DB', 0), 'name' => env('REDIS_CLIENT_NAME'), 'prefix' => env('REDIS_PREFIX', ''), 'tls' => env('REDIS_TLS', false), ], ],
Supported Config Mapping
The connector normalizes Laravel config into GLIDE connect arguments:
host/port->addressesaddresses(array) ->addressestlsorscheme=tls->use_tls=trueusername+password-> ACL credentialsiamblock -> IAM credentials +use_tls=truedatabase->database_idname->client_nameread_from->read_from(replica read routing; see Read Routing)client_az->client_az(availability zone for AZ-affinity routing)context->context(TLS stream context; array or resource)timeout(seconds) ->request_timeout(milliseconds)connection_timeout(seconds) ->advanced_config.connection_timeout(milliseconds)
Cluster-style configs are normalized into seed addresses and connected through the dedicated ValkeyGlideCluster
client via connectToCluster().
Runtime Behavior
Command execution goes through ValkeyGlideConnection::command().
- Idempotent commands can retry once on recognized transient connection errors
- Non-idempotent commands are not retried
- Laravel command events are dispatched (
CommandExecuted,CommandFailed) executeRaw()is supported viarawcommand- Phpredis-style
SET/EVALargument shapes are normalized throughrawcommand disconnect()delegates to GLIDEclose()
Prefix Compatibility
Prefixing is handled in the connection wrapper for supported command families:
- single-key commands (
GET,SET,HGET, etc.) - all-key commands (
MGET,DEL, etc.) - two-key commands (
RENAME, etc.) EVAL/EVALSHAkey segments
Read Routing
GLIDE can route read commands to replicas. Set read_from on the connection to one of the following strategies (both
the string name and the integer constant are accepted):
| Strategy | Value | Behavior |
|---|---|---|
primary |
0 |
All reads go to the primary (default) |
prefer_replica |
1 |
Reads prefer replicas, falling back to the primary |
az_affinity |
2 |
Reads prefer replicas in the same AZ as client_az |
az_affinity_replicas_and_primary |
3 |
Same-AZ affinity across replicas and the primary |
client_az is required for the AZ-affinity strategies.
'default' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'port' => (int) env('REDIS_PORT', 6379), 'read_from' => env('REDIS_READ_FROM', 'prefer_replica'), 'client_az' => env('REDIS_CLIENT_AZ'), ],
Timeouts and TLS Context
The GLIDE core defaults the request timeout to 250ms, which can be too short for managed services during warm-up. Configure timeouts in seconds (matching the phpredis convention); they are converted to milliseconds for GLIDE:
timeout(seconds) ->request_timeoutconnection_timeout(seconds) ->advanced_config.connection_timeout
Pass a custom TLS stream context (for custom CA certificates or verification settings) via the per-connection context
key. Both a config-array and a pre-built stream_context_create() resource are accepted:
'default' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), 'tls' => true, 'timeout' => 3.0, 'context' => [ 'ssl' => [ 'cafile' => '/path/to/ca.crt', 'verify_peer' => true, ], ], ],
Cluster Connections
Cluster connections use the dedicated ValkeyGlideCluster client, which follows cluster topology and slot routing.
Configure a cluster the standard Laravel way:
'redis' => [ 'client' => 'valkey-glide', 'clusters' => [ 'default' => [ ['host' => env('REDIS_HOST'), 'port' => (int) env('REDIS_PORT', 6379)], ], ], ],
Raw commands (EVAL / EVALSHA, phpredis-style SET with options) are routed to the primary that owns the affected
key's slot.
ElastiCache Serverless
AWS ElastiCache Serverless runs in cluster mode (single logical database, TLS required) and exposes the primary on port 6379 and the reader on port 6380. Configure it as a cluster with TLS, and optionally with replica read routing:
'redis' => [ 'client' => 'valkey-glide', 'clusters' => [ 'default' => [ [ 'host' => env('REDIS_HOST'), 'port' => (int) env('REDIS_PORT', 6379), 'tls' => true, 'read_from' => 'prefer_replica', 'timeout' => 3.0, ], ], ], ],
Keep the database index at 0 - cluster mode exposes only database 0. When using replica read routing, ensure the
security group allows both port 6379 (read/write) and 6380 (read-only).
Testing
The default suite is deterministic and requires no local Redis server:
composer test
The external suite exercises the real ext-valkey_glide extension against a live Valkey/Redis server. It is excluded
from the default run and must be invoked explicitly:
composer test:external
External integration coverage includes:
- extension/client availability and connect/close behavior
- connector/connection roundtrip behavior and retry semantics
- command-prefix behavior, including list-style key commands (
MGET) - Laravel cache roundtrip behavior, physical key writes, locks, and TTL edge cases
- Laravel queue push/pop behavior and physical queue key writes
- Laravel session roundtrip behavior and physical session key writes
The external suite reads connection details from optional environment variables:
VALKEY_GLIDE_TEST_HOSTVALKEY_GLIDE_TEST_PORTVALKEY_GLIDE_TEST_TLSVALKEY_GLIDE_TEST_USERNAMEVALKEY_GLIDE_TEST_PASSWORD
All available Composer scripts:
composer test # PHPUnit suite in parallel via Paratest (excludes external) composer test:external # external suite against a live Valkey/Redis server composer test:coverage # suite with Clover coverage output composer test:mutation # Infection mutation gate (min MSI 90) composer test:mutation:full # full mutation suite without thresholds composer check # static analysis and lint via qlty composer format # format via qlty composer smells # duplication / complexity smells via qlty composer bench # PHPBench suite over the command / config hot paths composer bench:ci # PHPBench with CI artifact dump composer bench:smoke # single-rev pass to verify every subject runs
Changelog
See CHANGELOG.md for a list of notable changes.
Contributing
Contributions are welcome. Please read CONTRIBUTING.md for guidelines on branching, commits, code quality, and pull requests.
Security
If you discover a security vulnerability, please report it responsibly. See SECURITY.md for the disclosure policy and contact details.
License
Licensed under the Apache License, Version 2.0.
sinemacula/laravel-valkey-glide 适用场景与选型建议
sinemacula/laravel-valkey-glide 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「laravel」 「glide」 「valkey」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sinemacula/laravel-valkey-glide 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sinemacula/laravel-valkey-glide 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sinemacula/laravel-valkey-glide 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Microservice RPC through message queues.
Glide image processing in a Symfony2 project
The CodeIgniter Redis package
贝嘟分布式缓存扩展
Simple integration of Glide with WordPress
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-02-19