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

add support for all hash field expiration commands #2742

Open
wants to merge 7 commits into
base: v5
Choose a base branch
from

Conversation

sjpotter
Copy link
Contributor

Description

adds the has field expiration commands - for testing purposes, need a docker container that has it in it.


Checklist

  • Does npm test pass with this change (including linting)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

@sjpotter sjpotter requested a review from leibale April 17, 2024 12:41
Copy link
Collaborator

@leibale leibale left a comment

Choose a reason for hiding this comment

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

Overall looking good, but:

  1. I've made some changes, please review them..
  2. Seems like HGETF and HSETF are missing

@sjpotter
Copy link
Contributor Author

sjpotter commented May 9, 2024

change look fine

@sjpotter
Copy link
Contributor Author

Overall looking good, but:

1. I've made some changes, please review them..

2. Seems like `HGETF` and `HSETF` are missing

wondering why you didn't do an enum like response for HEXPIRETIME?

@sjpotter
Copy link
Contributor Author

Overall looking good, but:

1. I've made some changes, please review them..

2. Seems like `HGETF` and `HSETF` are missing

wondering why you didn't do an enum like response for HEXPIRETIME?

I see why, as it returns a negative number on "error" (enum) and any positive number on "success", and can't capture that conception in typescript.

@sjpotter
Copy link
Contributor Author

otherwise changes looks fine, and I messed up initial tests, thanks for fixing.

@leibale
Copy link
Collaborator

leibale commented Jun 10, 2024

We can make an enum for HEXPIRETIME and use a type like

type x = 1 | 2 | number;

I think that some users will find the enum useful..

@sjpotter
Copy link
Contributor Author

We can make an enum for HEXPIRETIME and use a type like

type x = 1 | 2 | number;

I think that some users will find the enum useful..

so I tried something like that, but it seemed like it ended up being shown as just number (as number is a superset of 1/2)

@leibale
Copy link
Collaborator

leibale commented Jun 10, 2024

It's possible, but a bit more complicated than that
https://www.totaltypescript.com/tips/create-autocomplete-helper-which-allows-for-arbitrary-values

and even if we don't use that in the return type, I think that some users will still find the enum useful (something like reply === HASH_EXPIRATION.FIELD_DOES_NOT_EXISTS is more readable than reply === -2)

@sjpotter
Copy link
Contributor Author

I agree, but I can't seem to get omit to work with NumberReply as NumerReply expects a number subtype, but Omit doesn't seem to return an number that can be used by it, and when I created a type manually without NumberReply, it didn't seem to make a difference in practice, was still just number.

but yes, I created the enum to use, just unsure how to expose it to the user.

export const HASH_FIELD_EXPIRETIME = {
/** The field does not exist /
FIELD_NOT_EXISTS: -2,
/
* The field has no expiration time */
NO_EXPIRATION_TIME: -1,
} as const;

key: RedisArgument,
fields: RedisVariadicArgument,
seconds: number,
mode?: 'NX' | 'XX' | 'GT' | 'LT',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we do

interface HExpireOptions {
  mode?: 'NX' | 'XX' | 'GT' | 'LT';
}

for "future proofing" (in case there will be more optional arguments)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it doesn't really future proof, it just makes it easier if these options are shared between multiple commands. Unsure it adds that much.

transformArguments(key: RedisArgument, fields: RedisVariadicArgument) {
return pushVariadicArgument(['HTTL', key], fields);
},
transformReply: undefined as unknown as () => ArrayReply<NumberReply>
Copy link
Collaborator

Choose a reason for hiding this comment

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

the reply is array of

Integer reply: -2 if no such field exists in the provided hash key, or the provided key does not exist.
Integer reply: -1 if the field exists but has no associated expiration set.
Integer reply: the TTL in seconds.

should we create an "enum" (not the TS one) for the -2 and -1 values? IDK if I like having them anymore..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

an enum can have value to refrer to negative values by name. but isn't that what I did before ala

export const HASH_FIELD_EXPIRETIME = {
  /** The field does not exist /
  FIELD_NOT_EXISTS: -2,
  /* The field has no expiration time */
  NO_EXPIRATION_TIME: -1,
} as const;

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