-
Notifications
You must be signed in to change notification settings - Fork 991
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
feat: add HEXPIRE and FIELDEXPIRE #3842
feat: add HEXPIRE and FIELDEXPIRE #3842
Conversation
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.
Hi @NegatioN and thaaaank you for your contribution!
I left some comments mostly about adding a couple of test cases, some corner cases and some nits to avoid code duplication :)
Thank you again 🚀 💯
@NegatioN let me know when you addressed all the comments and I will rereview :) |
src/server/set_family.h
Outdated
@@ -33,6 +33,9 @@ class SetFamily { | |||
static int32_t FieldExpireTime(const DbContext& db_context, const PrimeValue& pv, | |||
std::string_view field); | |||
|
|||
static std::vector<long> SetFieldsExpireTime(const OpArgs& op_args, PrimeValue& pv, |
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.
our style guide requires that we pass output variables (pv) last and by pointer.
src/server/hset_family.h
Outdated
@@ -29,9 +29,14 @@ class HSetFamily { | |||
static int32_t FieldExpireTime(const DbContext& db_context, const PrimeValue& pv, | |||
std::string_view field); | |||
|
|||
static std::vector<long> SetFieldsExpireTime(const OpArgs& op_args, PrimeValue& pv, |
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.
our style guide requires that we pass output variables (pv) last and by pointer.
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.
Just to clarify, the signature should be like this?
static std::vector<long> SetFieldsExpireTime(const OpArgs& op_args, uint32_t ttl_sec, std::string_view key,
CmdArgList values, PrimeValue& pv)
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 think he wants:
static std::vector<long> SetFieldsExpireTime(const OpArgs& op_args, uint32_t ttl_sec, std::string_view key,
CmdArgList values, PrimeValue* pv)
Notice last argument, it's not a reference
but a pointer
. (That's from our style guide)
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.
Also @NegatioN I am fine with the PR once this is addressed. The rest of my comments are NIT.
LGTM! 🚀
@kostasrim I think this is ready for a review again now. |
src/server/family_utils.h
Outdated
template <typename O> | ||
static std::vector<long> ExpireElements(void* ptr, const facade::CmdArgList values, | ||
uint32_t ttl_sec) { | ||
O* owner = (O*)ptr; | ||
std::vector<long> res; |
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.
template <typename O> | |
static std::vector<long> ExpireElements(void* ptr, const facade::CmdArgList values, | |
uint32_t ttl_sec) { | |
O* owner = (O*)ptr; | |
std::vector<long> res; | |
template <typename DenseSet> | |
static std::vector<long> ExpireElements(DenseSet* owner, const facade::CmdArgList values, | |
uint32_t ttl_sec) { | |
std::vector<long> res; |
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.
that way you don't need:
- To cast a
void*
to the respective type - You can now call
ExpireElements(arg1, arg2)
without the<>
syntax. (that is, let the compiler automatically deduce this)
src/server/hset_family.h
Outdated
@@ -29,9 +29,14 @@ class HSetFamily { | |||
static int32_t FieldExpireTime(const DbContext& db_context, const PrimeValue& pv, | |||
std::string_view field); | |||
|
|||
static std::vector<long> SetFieldsExpireTime(const OpArgs& op_args, PrimeValue& pv, |
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 think he wants:
static std::vector<long> SetFieldsExpireTime(const OpArgs& op_args, uint32_t ttl_sec, std::string_view key,
CmdArgList values, PrimeValue* pv)
Notice last argument, it's not a reference
but a pointer
. (That's from our style guide)
|
||
OpResult<vector<long>> result = cntx->transaction->ScheduleSingleHopT(std::move(cb)); | ||
auto* rb = static_cast<RedisReplyBuilder*>(cntx->reply_builder()); | ||
if (result) { |
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.
This could be a function but its fine :)
@kostasrim Done |
LGTM and thank you for the contribution @NegatioN |
btw I have no access to merge the PR, so someone else has to do that for me @kostasrim :) |
I must say it was a pretty good PR for |
* add hexpire * add fieldexpire * add tests
Continuation of: #3780
To implement issue: #3027
Here's my suggestion for how to add the
FIELDEXPIRE
andHEXPIRE
commands. I tried to split it up similarly to howFieldTtl
does generic operations acrossset_family
andhset_family
.I've not added support for the optional prefixes
[NX | XX | GT | LT]
, as I see few other commands do it, and I also don't really need it. (Can probably be further work?)Responses from both commands are (per element queried):
-2
for non-existing key/field,0
if ttl is 0, and ttl gets set, normal success=1
I have a few questions at this point:
acl
-settings for the commands.Open for comments. Tagging @romange @kostasrim, since you're already familiar with the previous PR.