forked from mrnumber/ocaml-redis
-
Notifications
You must be signed in to change notification settings - Fork 33
support keepttl option in set #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tatchi
wants to merge
1
commit into
0xffea:master
Choose a base branch
from
tatchi:support-keepttl-set
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+63
−39
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,4 @@ | |
| *.exe | ||
| /result* | ||
| /socket/redis.sock | ||
| _opam | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1118,27 +1118,33 @@ module MakeClient(Mode: Mode) = struct | |
| let command = "MSETNX" :: (interleave items) in | ||
| send_request connection command >>= return_bool | ||
|
|
||
| let set connection ?ex:(ex=0) ?px:(px=0) ?nx:(nx=false) ?xx:(xx=false) key value = | ||
| let set connection ?ex:(ex=0) ?px:(px=0) ?nx:(nx=false) ?xx:(xx=false) ?keepttl:(keepttl=false) key value = | ||
| match (nx, xx) with | ||
| | (true, true) -> | ||
| IO.fail (Invalid_argument "SET command can contain only one of NX or XX options.") | ||
| | _ -> | ||
| let ex = match ex with | ||
| | 0 -> [] | ||
| | _ -> ["EX"; string_of_int ex] in | ||
| let px = match px with | ||
| | 0 -> [] | ||
| | _ -> ["PX"; string_of_int px] in | ||
| let nx = match nx with | ||
| | false -> [] | ||
| | true -> ["NX"] in | ||
| let xx = match xx with | ||
| | false -> [] | ||
| | true -> ["XX"] in | ||
| let base_command = [ "SET"; key; value; ] in | ||
| let args = List.concat [ex; px; nx; xx] in | ||
| 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.") | ||
| else | ||
| let ex = match ex with | ||
| | 0 -> [] | ||
| | _ -> ["EX"; string_of_int ex] in | ||
| let px = match px with | ||
| | 0 -> [] | ||
| | _ -> ["PX"; string_of_int px] in | ||
| let nx = match nx with | ||
| | false -> [] | ||
| | true -> ["NX"] in | ||
| let xx = match xx with | ||
| | false -> [] | ||
| | true -> ["XX"] in | ||
| let keepttl = match keepttl with | ||
| | false -> [] | ||
| | true -> ["KEEPTTL"] in | ||
| let base_command = [ "SET"; key; value; ] in | ||
| let args = List.concat [ex; px; nx; xx; keepttl] in | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we can have only one List.concat here? :) |
||
| let command = List.concat [base_command; args] in | ||
| send_request connection command >>= return_ok_or_nil | ||
|
|
||
| let setex connection key seconds value = | ||
| let seconds = string_of_int seconds in | ||
|
|
@@ -2012,27 +2018,33 @@ module MakeClient(Mode: Mode) = struct | |
| | _ -> assert false | ||
| ) responses | ||
|
|
||
| let set ?ex:(ex=0) ?px:(px=0) ?nx:(nx=false) ?xx:(xx=false) key value = | ||
| let set ?ex:(ex=0) ?px:(px=0) ?nx:(nx=false) ?xx:(xx=false) ?keepttl:(keepttl=false) key value = | ||
| match (nx, xx) with | ||
| | (true, true) -> | ||
| raise (Invalid_argument "SET command can contain only one of NX or XX options.") | ||
| | _ -> | ||
| let ex = match ex with | ||
| | 0 -> [] | ||
| | _ -> ["EX"; string_of_int ex] in | ||
| let px = match px with | ||
| | 0 -> [] | ||
| | _ -> ["PX"; string_of_int px] in | ||
| let nx = match nx with | ||
| | false -> [] | ||
| | true -> ["NX"] in | ||
| let xx = match xx with | ||
| | false -> [] | ||
| | true -> ["XX"] in | ||
| let base_command = [ "SET"; key; value; ] in | ||
| let args = List.concat [ex; px; nx; xx] in | ||
| let command = List.concat [base_command; args] in | ||
| command | ||
| if keepttl && (ex > 0 || px > 0) then | ||
| raise (Invalid_argument "SET command cannot combine KEEPTTL with EX or PX options.") | ||
| else | ||
| let ex = match ex with | ||
| | 0 -> [] | ||
| | _ -> ["EX"; string_of_int ex] in | ||
| let px = match px with | ||
| | 0 -> [] | ||
| | _ -> ["PX"; string_of_int px] in | ||
| let nx = match nx with | ||
| | false -> [] | ||
| | true -> ["NX"] in | ||
| let xx = match xx with | ||
| | false -> [] | ||
| | true -> ["XX"] in | ||
| let keepttl = match keepttl with | ||
| | false -> [] | ||
| | true -> ["KEEPTTL"] in | ||
| let base_command = [ "SET"; key; value; ] in | ||
| let args = List.concat [ex; px; nx; xx; keepttl] in | ||
| let command = List.concat [base_command; args] in | ||
| command | ||
|
|
||
| let del keys = | ||
| "DEL" :: keys | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -317,10 +317,11 @@ module type Client = sig | |
| (** Sets the given keys to their respective values. MSETNX will not perform any operation at all even if just a single key already exists. *) | ||
| val msetnx : connection -> (string * string) list -> bool IO.t | ||
|
|
||
| (** 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). *) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also a |
||
| val set : | ||
| connection -> | ||
| ?ex:int -> ?px:int -> ?nx:bool -> ?xx:bool -> | ||
| ?ex:int -> ?px:int -> ?nx:bool -> ?xx:bool -> ?keepttl:bool -> | ||
| string -> string -> bool IO.t | ||
|
|
||
| (** Set key to hold the string value and set key to timeout after a given number of seconds. *) | ||
|
|
@@ -803,7 +804,7 @@ module type Client = sig | |
|
|
||
| val empty : command | ||
|
|
||
| val set : ?ex:int -> ?px:int -> ?nx:bool -> ?xx:bool -> string -> string -> command | ||
| val set : ?ex:int -> ?px:int -> ?nx:bool -> ?xx:bool -> ?keepttl:bool -> string -> string -> command | ||
|
|
||
| (** Delete a key; returns the number of keys removed. *) | ||
| val del : string list -> command | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.