Skip to content

feat(object-cache): add Relay as a supported object cache driver - #1036

Open
faisalahammad wants to merge 1 commit into
litespeedtech:devfrom
faisalahammad:fix/906-relay-object-cache-driver
Open

faisalahammad wants to merge 1 commit into
litespeedtech:devfrom
faisalahammad:fix/906-relay-object-cache-driver

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Description

Add support for the Relay PHP extension (relay.so) as a third object cache driver option alongside Memcached and Redis in LiteSpeed Cache settings.

Relay is a Redis-compatible, shared-memory PHP extension that provides an in-memory cache layer at the PHP process level. It is API-compatible with phpredis for all object caching calls this plugin uses (connect, pconnect, auth, select, get, set, del, flushDb, rawCommand).

Closes #906

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (fixes multisite multi-switch option casting in conf.cls.php)

Proposed Changes

  1. src/base.cls.php:
    • Register O_OBJECT_KIND in _conf_multi_switch() to accept value 2 (Relay).
  2. src/conf.cls.php:
    • Fix network_update() multi-switch check so integer values (0/1/2) are preserved instead of being cast to boolean.
  3. src/object-cache.cls.php:
    • Change _cfg_method to integer representation (0 = Memcached, 1 = Redis, 2 = Relay).
    • Add _resolve_driver() and _driver_cls_exists() helper methods.
    • Update _connect() to instantiate \Relay\Relay for value 2, skip phpredis-only options, and validate PING responses ('PONG', '+PONG', true).
    • Route get(), set(), delete(), and flush() through Relay when selected.
    • Add \Exception catch block to safely catch \Relay\Exception (which does not extend \RedisException).
    • Make _redis_error() driver-aware for log messages and admin notices.
  4. tpl/cache/settings_inc.object.tpl.php:
    • Add Relay extension status badge to the status display row.
    • Expand the Method radio switch to 3 options (Memcached, Redis, Relay).
    • Update jQuery port auto-fill logic so Relay (value 2) defaults to port 6379.

Verification & Testing

  • PHPCS: Ran composer run sniff-check — 0 errors, 0 warnings (exit 0).
  • PHP Lint: Verified syntax (php -l) on all modified files.
  • Backward Compatibility: Existing sites using Memcached (0) or Redis (1) are unaffected. If Relay is selected but relay.so is not installed, class_exists() check keeps object cache safely disabled.

@faisalahammad
faisalahammad force-pushed the fix/906-relay-object-cache-driver branch 2 times, most recently from 64c0793 to 47f2535 Compare August 9, 2026 13:08
@faisalahammad
faisalahammad changed the base branch from master to dev August 9, 2026 13:08
Add support for the Relay PHP extension (relay.so) as a third object
cache driver alongside the existing Redis and Memcached options.

Relay is a Redis-compatible, shared-memory PHP extension that provides
an in-memory cache layer at the PHP process level. It is API-compatible
with phpredis for the calls this plugin makes.

Changes:
- src/base.cls.php: Register O_OBJECT_KIND in _conf_multi_switch() to
  accept value 2 (Relay). Values 0 and 1 remain backward-compatible.
- src/conf.cls.php: Fix multisite multi-switch option handling in
  network_update() so integer values (0/1/2) are preserved.
- src/object-cache.cls.php:
  - Change _cfg_method to an integer (0/1/2) instead of boolean.
  - Add _resolve_driver() to map the integer to a class name.
  - Add _driver_cls_exists() to check driver availability.
  - In _connect(), instantiate \Relay\Relay for value 2; skip
    phpredis-only OPT_REPLY_LITERAL for Relay. Accept '+PONG' and boolean
    true as valid PING responses.
  - Extend get(), set(), delete(), and flush() to treat Relay the same
    as Redis (they share the same wire protocol API).
  - Catch \Exception in addition to \RedisException to gracefully handle
    \Relay\Exception.
  - Make _redis_error() driver-aware (logs 'Relay' vs 'Redis').
- tpl/cache/settings_inc.object.tpl.php:
  - Show Relay extension status badge in the status row.
  - Expand the Method switch from 2 options to 3 (Memcached/Redis/Relay).
  - Update port auto-fill JS: Relay (value 2) also defaults to 6379.

Closes litespeedtech#906
@faisalahammad
faisalahammad force-pushed the fix/906-relay-object-cache-driver branch from 47f2535 to b32100d Compare August 9, 2026 13:11
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.

Support Relay as Object Cache driver for Redis

1 participant