diff --git a/src/Redis.php b/src/Redis.php index 7119307..e6aa651 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -102,6 +102,33 @@ public function getOptions(): RedisOptions return $this->options; } + /** + * @psalm-api + * @return non-empty-string|null + */ + 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) || $persistentId === '') { + return null; + } + + return $persistentId; + } + /** * {@inheritDoc} */ diff --git a/src/RedisOptions.php b/src/RedisOptions.php index fd03019..db99951 100644 --- a/src/RedisOptions.php +++ b/src/RedisOptions.php @@ -74,6 +74,7 @@ final class RedisOptions extends AdapterOptions * The namespace separator */ protected string $namespaceSeparator = ':'; + /** @var non-empty-string|null */ protected string|null $persistentId; protected string $redisVersion = ''; @@ -128,6 +129,9 @@ public function getNamespaceSeparator(): string return $this->namespaceSeparator; } + /** + * @return non-empty-string|null + */ public function getPersistentId(): string|null { return $this->persistentId;