Skip to content

Add circuit breaker configuration support - #277

Merged
jeremyprime merged 2 commits into
valkey-io:mainfrom
jeremyprime:feat/circuit-breaker-config
Jul 30, 2026
Merged

Add circuit breaker configuration support#277
jeremyprime merged 2 commits into
valkey-io:mainfrom
jeremyprime:feat/circuit-breaker-config

Conversation

@jeremyprime

Copy link
Copy Markdown
Collaborator

Summary

Add circuit breaker configuration support to the PHP client, matching the existing implementation in Java, Python, Node, and Go (valkey-io/valkey-glide#6050). The circuit breaker logic lives in the Rust core; this change adds the config array parameter, serializes it to protobuf, and surfaces a CircuitBreakerException type to callers.

Issue link

Closes #238

Features / Behaviour Changes

  • New ?array $circuit_breaker parameter on ValkeyGlide::connect() and ValkeyGlideCluster::__construct()
  • New CircuitBreakerException class (extends ValkeyGlideException) thrown when the circuit breaker is open
  • Configuration keys: window_size_ms, failure_rate_threshold, min_errors, open_timeout_ms, count_timeouts, consecutive_successes
  • All parameters optional with sensible defaults matching other clients

Implementation

  • common.h: Added valkey_glide_circuit_breaker_config_t struct, constants, and plumbed into base config
  • valkey_glide.c: Parse circuit breaker array, register exception class, cleanup on free
  • valkey_glide_core_commands.c: Serialize config to ClientCircuitBreakerConfig protobuf message (field 30)
  • valkey_glide_commands_common.h: Dispatch CircuitBreakerException when command_error_type == CircuitBreakerOpen
  • Stubs and mock constructors updated for both standalone and cluster

Testing

  • New unit tests added to ConnectionRequestTest.php:
    • testCircuitBreakerStandaloneDefaults: empty array uses defaults
    • testCircuitBreakerClusterDefaults: same for cluster
    • testCircuitBreakerStandaloneCustomValues: all fields customized
    • testCircuitBreakerClusterCustomValues: same for cluster
    • testCircuitBreakerNotSetByDefault: null when not provided

Checklist

  • This Pull Request is related to one issue.
  • Commit message has a detailed description of what changed and why.
  • Tests are added or updated.
  • CHANGELOG.md and documentation files are updated.
  • Destination branch is correct - main or release
  • Create merge commit if merging release branch into main, squash otherwise.

Comment thread valkey_glide_commands_common.h Outdated
Comment thread tests/ConnectionRequestTest.php
Comment thread valkey_glide.c

@currantw currantw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed to 7ba5343.

Comment thread common.h
Comment thread valkey_glide_ft_common.c Outdated
Comment thread tests/ConnectionRequestTest.php
@jeremyprime
jeremyprime force-pushed the feat/circuit-breaker-config branch from 7ba5343 to cec7239 Compare July 28, 2026 20:28
@currantw
currantw self-requested a review July 29, 2026 17:11

@currantw currantw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed to cec7239.
Looks good ✅
Thanks for replying to all my comments.
Will update C# GLIDE client to use a consistent approach.

Signed-off-by: Jeremy Parr-Pearson <jeremy.parr-pearson@improving.com>
Signed-off-by: Jeremy Parr-Pearson <jeremy.parr-pearson@improving.com>
@jeremyprime
jeremyprime force-pushed the feat/circuit-breaker-config branch from cec7239 to de33eed Compare July 30, 2026 18:46
@jeremyprime
jeremyprime merged commit 1a7515c into valkey-io:main Jul 30, 2026
48 of 53 checks passed
@jeremyprime
jeremyprime deleted the feat/circuit-breaker-config branch July 30, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task] Add circuit breaker configuration support for PHP

3 participants