Skip to main content

Relay

Notes:

  • Dragonfly v1.14+ and the RESP3 protocol are required for this integration.
  • See more details about the CLIENT TRACKING command that enables this integration.

Introduction

Relay is a revolutionary PHP extension that combines the functionalities of a Redis client with an advanced shared in-memory cache, offering exceptional caching performance enhancements.

Relay can be used as a drop-in replacement for phpredis. By maintaining a highly-efficient partial replica of Redis data in the PHP master process memory and utilizing real-time cache invalidation and updates, Relay significantly outperforms traditional clients. Tailored for shared environments, it allows for precise memory management, employing LRU and LFU eviction policies to optimize performance. Relay supports seamless integration across major platforms like Laravel, WordPress, Magento, and Drupal without requiring code modifications.

Dragonfly is highly compatible with Redis, and Relay can be effortlessly used with Dragonfly (v1.14+) with even better performance and efficiency.

Using Relay with Dragonfly

1. Dragonfly Initialization

There are several options available to get Dragonfly up and running quickly. Assuming you have a local Dragonfly binary, you can run Dragonfly with the following command:

$> ./dragonfly --bind localhost --port 6379

2. Relay Installation

For different platforms, you can install Relay by following the instructions in their documentation.

3. Start Using Relay with Dragonfly

Once you have Dragonfly and Relay set up, you can start using Relay with Dragonfly in code. For more information on how to use Relay in terms of configuration, integrations, events, and APIs, please refer to the Relay documentation.

// Assume Dragonfly is running locally on the default port.
$relay = new Relay(host: '127.0.0.1', port: 6379);

// Fetch the user count from Relay's memory, or from Dragonfly if the key has not been cached, yet.
$users = $relay->get('users:count');

// Listen to all invalidation events.
$relay->onInvalidated(function (Relay\Event $event) use ($users) {
if ($event->key === 'users:count') {
$users = null;
}
});

Useful Resources & Benchmarks