From 1b1f6aafb78ae17328a6cf66a2c471bc94df1f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Fri, 21 Jun 2024 23:07:20 +0200 Subject: [PATCH] feature: add `Redis#getPersistentId` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we removed the magic which automagically set the persistent id to the options, this method is to provide the persistent id in case we connected to redis using the persistent flag. If the persistent ID was provided via config, the ID from the config is returned. Otherwise, we return the persistent ID from `ext-redis`. In case `update` flag is provided, the persistent ID is always returned from `ext-redis`. Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com> --- src/Redis.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Redis.php b/src/Redis.php index 7119307..89319d6 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -102,6 +102,29 @@ public function getOptions(): RedisOptions return $this->options; } + public function getPersistentId(bool $update = false): ?string + { + $options = $this->getOptions(); + + if (!$options->isPersistent()) { + return null; + } + + if ($update === false) { + $persistentId = $options->getPersistentId(); + if ($persistentId !== null) { + return $persistentId; + } + } + + $persistentId = $this->getRedisResource()->getPersistentID(); + if (!is_string($persistentId)) { + return null; + } + + return $persistentId; + } + /** * {@inheritDoc} */