diff --git a/src/JetStream/KeyValue/Bucket.php b/src/JetStream/KeyValue/Bucket.php index 8231a23..3759c9f 100644 --- a/src/JetStream/KeyValue/Bucket.php +++ b/src/JetStream/KeyValue/Bucket.php @@ -71,10 +71,19 @@ public function get(string $key, int $revision = 0): ?Entry * @param non-empty-string $key * @return non-negative-int */ - public function put(string $key, ?string $value = null): int + public function put(string $key, ?string $value = null, ?TimeSpan $ttl = null): int { + if ($ttl !== null) { + $headers = (new Headers())->with(Header\MsgTtl::Header, $ttl); + } else { + $headers = null; + } + return $this->js - ->publish($this->prefixedSubject($key), new Message($value)) + ->publish($this->prefixedSubject($key), new Message( + payload: $value, + headers: $headers, + )) ->seq ?? throw new \LogicException('Sequence expected on kv publish'); }