1<?php
2/**
3 * Copyright © 2019-2026 Rhubarb Tech Inc. All Rights Reserved.
4 *
5 * The Object Cache Pro Software and its related materials are property and confidential
6 * information of Rhubarb Tech Inc. Any reproduction, use, distribution, or exploitation
7 * of the Object Cache Pro Software and its related materials, in whole or in part,
8 * is strictly forbidden unless prior permission is obtained from Rhubarb Tech Inc.
9 *
10 * In addition, any reproduction, use, distribution, or exploitation of the Object Cache Pro
11 * Software and its related materials, in whole or in part, is subject to the End-User License
12 * Agreement accessible in the included `LICENSE` file, or at: https://objectcache.pro/eula
13 */
14
15declare(strict_types=1);
16
17namespace RedisCachePro\Clients;
18
19use OpenTelemetry\API\Trace\TracerInterface;
20use OpenTelemetry\API\Trace\TracerProviderInterface;
21
22/**
23 * @mixin \Relay\Relay
24 * @property \Relay\Relay $client
25 */
26class Relay extends Client
27{
28 use Concerns\PhpRedisTransactions;
29
30 public const OPT_SERIALIZER = 1;
31
32 public const OPT_PREFIX = 2;
33
34 public const OPT_READ_TIMEOUT = 3;
35
36 public const OPT_SCAN = 4;
37
38 public const OPT_TCP_KEEPALIVE = 6;
39
40 public const OPT_COMPRESSION = 7;
41
42 public const OPT_COMPRESSION_LEVEL = 9;
43
44 public const OPT_REPLY_LITERAL = 8;
45
46 public const OPT_NULL_MULTIBULK_AS_NULL = 10;
47
48 public const OPT_MAX_RETRIES = 11;
49
50 public const OPT_BACKOFF_ALGORITHM = 12;
51
52 public const OPT_BACKOFF_BASE = 13;
53
54 public const OPT_BACKOFF_CAP = 14;
55
56 public const OPT_PHPREDIS_COMPATIBILITY = 100;
57
58 public const OPT_CLIENT_INVALIDATIONS = 101;
59
60 public const OPT_ALLOW_PATTERNS = 102;
61
62 public const OPT_IGNORE_PATTERNS = 103;
63
64 public const ATOMIC = 0;
65
66 public const MULTI = 1;
67
68 public const PIPELINE = 2;
69
70 public const COMPRESSION_NONE = 0;
71
72 public const COMPRESSION_LZF = 1;
73
74 public const COMPRESSION_ZSTD = 2;
75
76 public const COMPRESSION_LZ4 = 3;
77
78 public const SERIALIZER_NONE = 0;
79
80 public const SERIALIZER_PHP = 1;
81
82 public const SERIALIZER_IGBINARY = 2;
83
84 public const SERIALIZER_MSGPACK = 3;
85
86 public const SERIALIZER_JSON = 4;
87
88 public const BACKOFF_ALGORITHM_DEFAULT = 0;
89
90 public const BACKOFF_ALGORITHM_DECORRELATED_JITTER = 1;
91
92 public const BACKOFF_ALGORITHM_FULL_JITTER = 2;
93
94 public const SCAN_NORETRY = 0;
95
96 public const SCAN_RETRY = 1;
97
98 public const SCAN_PREFIX = 2;
99
100 public const SCAN_NOPREFIX = 3;
101
102 /**
103 * Creates an OpenTelemetry tracer from given tracer provider.
104 *
105 * @param TracerProviderInterface $tracerProvider
106 * @return TracerInterface
107 */
108 protected function createOpenTelemetryTracer(TracerProviderInterface $tracerProvider): TracerInterface
109 {
110 return $tracerProvider->getTracer('Relay', (string) \phpversion('relay'));
111 }
112
113 /**
114 * Returns the number of bytes allocated, or `0` in client-only mode.
115 *
116 * @return int
117 */
118 public function maxMemory()
119 {
120 if (\method_exists($this->client, 'maxMemory')) {
121 return $this->client->maxMemory(); // >= v0.5.0
122 }
123
124 if (\method_exists($this->client, 'memory')) {
125 return $this->client->memory(); // v0.4.6
126 }
127
128 return (int) \ini_get('relay.maxmemory'); // <= 0.4.5
129 }
130
131 /**
132 * Pass `scan()` calls to the client with iterator reference.
133 *
134 * @param mixed $iterator
135 * @param mixed $match
136 * @param int $count
137 * @return mixed
138 */
139 public function scan(&$iterator, $match = null, $count = 0)
140 {
141 return $this->{$this->callback}(function () use (&$iterator, $match, $count) {
142 return $this->client->scan($iterator, $match, $count);
143 }, 'scan');
144 }
145
146 /**
147 * Pass `hscan()` calls to the client with iterator reference.
148 *
149 * @param mixed $key
150 * @param mixed $iterator
151 * @param mixed $match
152 * @param int $count
153 * @return mixed
154 */
155 public function hscan($key, &$iterator, $match = null, $count = 0)
156 {
157 return $this->{$this->callback}(function () use ($key, &$iterator, $match, $count) {
158 return $this->client->hscan($key, $iterator, $match, $count);
159 }, 'hscan');
160 }
161
162 /**
163 * Pass `sscan()` calls to the client with iterator reference.
164 *
165 * @param mixed $key
166 * @param mixed $iterator
167 * @param mixed $match
168 * @param int $count
169 * @return mixed
170 */
171 public function sscan($key, &$iterator, $match = null, $count = 0)
172 {
173 return $this->{$this->callback}(function () use ($key, &$iterator, $match, $count) {
174 return $this->client->sscan($key, $iterator, $match, $count);
175 }, 'sscan');
176 }
177
178 /**
179 * Pass `zscan()` calls to the client with iterator reference.
180 *
181 * @param mixed $key
182 * @param mixed $iterator
183 * @param mixed $match
184 * @param int $count
185 * @return mixed
186 */
187 public function zscan($key, &$iterator, $match = null, $count = 0)
188 {
189 return $this->{$this->callback}(function () use ($key, &$iterator, $match, $count) {
190 return $this->client->zscan($key, $iterator, $match, $count);
191 }, 'zscan');
192 }
193
194 /**
195 * Returns the adaptive cache object.
196 *
197 * @return \Relay\AdaptiveCache|false
198 */
199 public function adaptiveCache()
200 {
201 return $this->client->adaptiveCache ?? false;
202 }
203}
204