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} */