Skip to content

Add SetArgs command #1662

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

Merged
merged 13 commits into from
Feb 17, 2021
Merged

Add SetArgs command #1662

merged 13 commits into from
Feb 17, 2021

Conversation

ynden
Copy link
Contributor

@ynden ynden commented Feb 16, 2021

SetArgs supports all the SET command options.
It is the alternative to the Set function when the user wants more control over the SET options.

@@ -1169,7 +1374,7 @@ var _ = Describe("Commands", func() {
Expect(val).To(Equal("hello"))

Eventually(func() error {
return client.Get(ctx, "foo").Err()
return client.Get(ctx, "key").Err()
Copy link
Contributor Author

@ynden ynden Feb 16, 2021

Choose a reason for hiding this comment

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

I think it should be "key" and not "foo", since we want to test that "key" expired correctly.
The test succeeded because "foo" didn't exist here, so it was always nil.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for fixing this 👍

commands.go Outdated
}

// SetWithArgs provides a way to call the SET command with SetArgs arguments.
func (c cmdable) SetWithArgs(ctx context.Context, key string, value interface{}, a *SetArgs) *StatusCmd {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's call this SetArgs with we already have such name and it is better to follow one convention.

commands.go Outdated
@@ -788,6 +788,50 @@ func (c cmdable) Set(ctx context.Context, key string, value interface{}, expirat
return cmd
}

// SetArgs provides arguments for the SetWithArgs command.
//
// Mode can be `NX` or `XX` or empty.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be a comment on Mode string field. And similar for Zero and Get.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I improved the readability

commands.go Outdated
// When Get is true, the command returns the old value stored at key, or nil when key did not exist.
type SetArgs struct {
Mode string
ExpireAt time.Duration
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe ExpireAt should be called TTL.

And there is no support for EXAT timestamp|PXAT milliseconds-timestamp. II is fine if you decide not to support it in this PR, but I believe we need:

TTL time.Duration // for px/ex
ExpireAt time.Time // for pxat/exat

commands.go Outdated
} else {
args = append(args, "ex", formatSec(ctx, a.ExpireAt))
}
} else if a.ExpireAt == KeepTTL {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer this to be KeepTTL bool field.

if a.KeepTTL { ... }

It is more explicit and we have both TTL and ExplireAt which can be confusing.

@vmihailenco
Copy link
Collaborator

Thanks. I've left few comments but overall this is looking good. Test coverage is impressing 👍

@ynden
Copy link
Contributor Author

ynden commented Feb 16, 2021

Thank you for your review! I'll look at this.

@ynden ynden changed the title Add SetWithArgs command Add SetArgs command Feb 16, 2021
@vmihailenco vmihailenco merged commit 7b7f9d6 into redis:master Feb 17, 2021
@vmihailenco
Copy link
Collaborator

Thanks 👍 I will experiment with API a bit too...

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