Skip to content
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

Added support for hash field expiration commands #1456

Draft
wants to merge 6 commits into
base: v2.x
Choose a base branch
from

Conversation

vladvildanov
Copy link
Contributor

@vladvildanov vladvildanov commented Apr 29, 2024

This PR adds new commands operates on hash field expiration functionality

@vladvildanov vladvildanov requested review from tillkruss and a team as code owners April 29, 2024 12:37
@vladvildanov vladvildanov marked this pull request as draft April 29, 2024 12:37
@vladvildanov
Copy link
Contributor Author

vladvildanov commented Apr 29, 2024

PR still on draft, until:

  • Redis unstable docker image will support given functionality

@coveralls
Copy link

coveralls commented Apr 29, 2024

Coverage Status

coverage: 80.553% (+0.3%) from 80.289%
when pulling d107d90 on vladvildanov:vv-hash-field-expiration
into cbef710 on predis:v2.x.

@@ -165,7 +175,10 @@
* @method $this hrandfield(string $key, int $count = 1, bool $withValues = false)
* @method $this hscan($key, $cursor, array $options = null)
* @method $this hset($key, $field, $value)
* @method $this hsetf(string $key, array $keyValuePairs, HSetFArguments $arguments = null)
Copy link

Choose a reason for hiding this comment

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

Call keyValuePairs dictionary, like in hmset?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense

@@ -174,7 +184,10 @@
* @method array hrandfield(string $key, int $count = 1, bool $withValues = false)
* @method array hscan(string $key, $cursor, array $options = null)
* @method int hset(string $key, string $field, string $value)
* @method mixed hsetf(string $key, array $keyValuePairs, HSetFArguments $arguments = null)
Copy link

Choose a reason for hiding this comment

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

Same here, use same naming like in hmset, i.e. dictionary?

/**
* Set the modifier that defines a behaviour on expiration.
*
* NX for each specified field set expiration only when the field has no expiration
Copy link

Choose a reason for hiding this comment

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

Being picky here, missing end dot at two sentences. And some more at the other method below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it

/**
* @var array
*/
protected $expireModifierEnum = [
Copy link

Choose a reason for hiding this comment

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

In my mind these two don't belong together. The {NX,XX,GT,LT} set is for overwriting rules, while {EX,PX,EXAT,PXAT} are basically just parameter name in compact form. For example {NX,XX,GT,LT} applies to other hash expiration commands, while the other set does not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So something like overrideModifierEnum sounds better?

*/
public function setPersist(): self
{
if (!empty(array_intersect($this->ttlModifierEnum, $this->arguments))) {
Copy link

Choose a reason for hiding this comment

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

What if someone first calls setPersist and then calls setTtlModifier?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, let's add the same kind of check on the other side

if (!in_array(strtoupper($modifier), $this->fieldModifierEnum, true)) {
throw new UnexpectedValueException('Incorrect field modifier value');
}

Copy link

Choose a reason for hiding this comment

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

Check that at most one modifier from the group is used.

if (!in_array(strtoupper($modifier), $this->getModifierEnum, true)) {
throw new UnexpectedValueException('Incorrect get modifier value');
}

Copy link

Choose a reason for hiding this comment

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

Check that at most one modifier from the group is used.

*/
public function enableKeepTTL(): self
{
if (!empty(array_intersect($this->ttlModifierEnum, $this->arguments))) {
Copy link

Choose a reason for hiding this comment

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

Same like for HGETF, what if someone first enables keepTtl and then calls setTtlModifierEnum? There should be a check on the other side too?


use Predis\Command\Command as RedisCommand;

class HEXPIRETIME extends RedisCommand
Copy link

Choose a reason for hiding this comment

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

I think this one too has the {NX,XX,LT,GT} flags. Maybe it should extend HEXPIRE?

@@ -72,7 +72,7 @@ class MasterSlaveReplication implements ReplicationInterface
/**
* {@inheritdoc}
*/
public function __construct(ReplicationStrategy $strategy = null)
public function __construct(?ReplicationStrategy $strategy = null)
Copy link

Choose a reason for hiding this comment

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

An idea: put these changes not strictly related to hash field expiration in a separate PR, to avoid noise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's already a PR with this changes, I'm waiting for approval and then rebase this branch

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

Successfully merging this pull request may close these issues.

None yet

3 participants