Skip to content

Using Relay

Till Krüss edited this page Mar 2, 2023 · 24 revisions

THIS PAGE IS A ROUGH DRAFT FOR THE PENDING 3.0 RELEASE

As of v3.0, Predis comes with a native integration for the Relay PHP extension, which brings major performance gains by:

  1. caching a partial replica of the Redis dataset in PHP shared runtime memory
  2. supporting fast data compression to reduce network and Redis memory usage by ~75%

Using Relay

Using Relay is as simple as installing the extension and defining the connection:

$client = new Predis\Client('tcp://127.0.0.1', [
    'connections' => 'relay',
]);

Compatibility

When using Relay, please note that:

  • Relay will ignore the exceptions option and always throw when error occur
  • Relay treats all connections as persistent and the persistent option is ignored
  • Transactions
  • The Predis integration has not been tested with aggregate connections (such as Sentinel or Cluster)
  • Some commands are currently unsupported:
    • MONITOR
    • WATCH / UNWATCH
    • SUBSCRIBE / UNSUBSCRIBE
    • PSUBSCRIBE / PUNSUBSCRIBE_Test
    • PUBLISH
    • COMMAND (WIP)

Search for the relay-incompatible group in the test suite to see which tests exactly don't pass.

(WIP) Serialization

  • supported algorithms: php, json, msgpack, igbinary
  • when serializing php objects, you must use php / igbinary
  • works in combination with compression option

(WIP) Data compression

  • supported algorithms: lzf, lz4, zstd
  • works with serializer option

Event callbacks

$client = new Predis\Client('tcp://127.0.0.1', [
    'connections' => 'relay',
]);

$client->getConnection()
    ->getClient()
    ->listen(function (\Relay\Event $event) {
        match ($event->type) {
            $event::Flushed => flushLocalCache(),
            $event::Invalidated => deleteKeyFromCache($event->key),
        };
    });

Clone this wiki locally