-
Notifications
You must be signed in to change notification settings - Fork 30
Add HSETEX #246
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
jogehl
wants to merge
4
commits into
valkey-io:main
Choose a base branch
from
jogehl:main
base: main
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.
Open
Add HSETEX #246
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
|
|
@@ -5055,6 +5055,78 @@ def hsetnx(self, name: str, key: str, value: str) -> Union[Awaitable[bool], bool | |
| """ | ||
| return self.execute_command("HSETNX", name, key, value) | ||
|
|
||
| def hsetex( | ||
| self, | ||
| name: str, | ||
| key: Optional[str] = None, | ||
| value: Optional[str] = None, | ||
| mapping: Optional[dict] = None, | ||
| items: Optional[list] = None, | ||
| ex: Union[ExpiryT, None] = None, | ||
| px: Union[ExpiryT, None] = None, | ||
| exat: Union[AbsExpiryT, None] = None, | ||
| pxat: Union[AbsExpiryT, None] = None, | ||
| keepttl: bool = False, | ||
| nx: bool = False, | ||
| xx: bool = False, | ||
| fnx: bool = False, | ||
| fxx: bool = False, | ||
| ) -> Union[Awaitable[bool], bool]: | ||
| """ | ||
| Set key to value within hash ``name``, | ||
| ``mapping`` accepts a dict of key/value pairs to be added to hash ``name``. | ||
| ``items`` accepts a list of key/value pairs to be added to hash ``name``. | ||
| Set expiration options for the hash fields. | ||
|
|
||
| For more information see https://valkey.io/commands/hsetex | ||
| """ | ||
|
|
||
| if key is None and not mapping and not items: | ||
| raise DataError("'hsetex' with no key value pairs") | ||
|
|
||
| if int(keepttl) + sum(arg is not None for arg in [ex, px, exat, pxat]) > 1: | ||
| raise DataError( | ||
| "Only one of 'ex', 'px', 'exat', 'pxat', or 'keepttl' can be specified." | ||
| ) | ||
| if nx and xx: | ||
| raise DataError("Only one of 'nx' or 'xx' can be specified.") | ||
| if fnx and fxx: | ||
| raise DataError("Only one of 'fnx' or 'fxx' can be specified.") | ||
| pieces = [] | ||
| if ex is not None: | ||
| pieces.extend(["EX", ex]) | ||
| if px is not None: | ||
| pieces.extend(["PX", px]) | ||
| if exat is not None: | ||
| pieces.extend(["EXAT", exat]) | ||
| if pxat is not None: | ||
mkmkme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pieces.extend(["PXAT", pxat]) | ||
| if nx: | ||
| pieces.append("NX") | ||
| if xx: | ||
mkmkme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pieces.append("XX") | ||
| if fnx: | ||
| pieces.append("FNX") | ||
| if fxx: | ||
| pieces.append("FXX") | ||
mkmkme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pieces.append("FIELDS") | ||
| if key is not None and value is not None: | ||
| pieces.append(1) # for one field | ||
| pieces.append(key) | ||
| pieces.append(value) | ||
| if mapping: | ||
| pieces.append(len(mapping)) | ||
| for key, value in mapping.items(): | ||
| if key is None or value is None: | ||
| raise DataError("'hsetex' mapping contains None key or value") | ||
| pieces.append(key) | ||
| pieces.append(value) | ||
| if items: | ||
|
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. Probably checking for only one of |
||
| pieces.append(len(items) // 2) | ||
| pieces.extend(items) | ||
|
|
||
| return self.execute_command("HSETEX", name, *pieces) | ||
|
|
||
| def hmset(self, name: str, mapping: dict) -> Union[Awaitable[str], str]: | ||
| """ | ||
| Set key to value within hash ``name`` for each corresponding | ||
|
|
||
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.
Could you also add some tests that would check at least
EXandPX?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.
I have tried this but for this the command HTTL is not implemented yet. Maybe it should be worth to include also this command?
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.
If you could handle this, I would greatly appreciate it! :)
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.
If you don't have time for this, you can ignore this for now. I can add the HTTL and add the corresponding tests later