Skip to content

support keepttl option in set#95

Open
tatchi wants to merge 1 commit into0xffea:masterfrom
tatchi:support-keepttl-set
Open

support keepttl option in set#95
tatchi wants to merge 1 commit into0xffea:masterfrom
tatchi:support-keepttl-set

Conversation

@tatchi
Copy link

@tatchi tatchi commented Mar 6, 2026

add support for keepttl option in set

KEEPTTL -- Retain the time to live associated with the key.

https://redis.io/docs/latest/commands/set/

Copy link
Collaborator

@c-cube c-cube left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor changes but this is looking good! :)

let command = List.concat [base_command; args] in
send_request connection command >>= return_ok_or_nil
if keepttl && (ex > 0 || px > 0) then
IO.fail (Invalid_argument "SET command cannot combine KEEPTTL with EX or PX options.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
IO.fail (Invalid_argument "SET command cannot combine KEEPTTL with EX or PX options.")
IO.fail (Invalid_argument "Redis.set: command cannot combine KEEPTTL with EX or PX options.")

| false -> []
| true -> ["KEEPTTL"] in
let base_command = [ "SET"; key; value; ] in
let args = List.concat [ex; px; nx; xx; keepttl] in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can have only one List.concat here? :)


(** Set key to hold the string value. *)
(** Set key to hold the string value.
@param keepttl retain the existing TTL on the key (since Redis 6.0). *)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also a @since for the library version, please!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants